How do I enable high-resolution alternatives for the system font in iOS?
1 answer
I was able to find a solution for activating high resolution alternatives in a UITextView.
// TextViewController.swift
import UIKit
class TextViewController: UIViewController, UITextViewDelegate {
// MARK: - Properties
@IBOutlet weak var textView: UITextView!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureTextView()
}
// MARK: - Configuration
func configureTextView() {
// Activate high-legibility alternates for system font.
let systemFontDescriptor = UIFont.systemFont(ofSize: 17).fontDescriptor
let highLegibilityFontDescriptor = systemFontDescriptor.addingAttributes(
[
UIFontDescriptorFeatureSettingsAttribute:
[
[
UIFontFeatureTypeIdentifierKey: kStylisticAlternativesType,
UIFontFeatureSelectorIdentifierKey: kStylisticAltSixOnSelector,
],
]
]
)
textView.font = UIFont(descriptor: highLegibilityFontDescriptor, size: 17)
}
}
+1
source to share