Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
///optional type in case if you want turn off acessability support
private let acessabilitySettings: DynamicTypeSettings? = DynamicTypeSettings()
private class DynamicTypeSettings {
let maxPointSizeScaleFactor: CGFloat
init(maxPointSizeScaleFactor: CGFloat = 1.25) {
self.maxPointSizeScaleFactor = maxPointSizeScaleFactor
UILabel.appearance().adjustsFontForContentSizeCategory = true
UITextField.appearance().adjustsFontForContentSizeCategory = true
}
}
// [Family, Size, CustomWeight enums](https://gist.github.com/popcornomnom/5288be0c003fedff3e9d43c332837dca)
convenience init(_ family: Family = .defaultFamily,
_ size: Size, _ weight: CustomWeight) {
if let acessabilitySettings = acessabilitySettings {
let originalFont = UIFont(name: UIFont.stringName(family, weight), size: size.rawValue)!
let scaledFont = UIFontMetrics.default.scaledFont(for: originalFont,
maximumPointSize: originalFont.pointSize *
acessabilitySettings.maxPointSizeScaleFactor)
self.init(descriptor: scaledFont.fontDescriptor, size: scaledFont.pointSize)
} else {
self.init(name: UIFont.stringName(family, weight), size: _size)!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.