Skip to content

Instantly share code, notes, and snippets.

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](
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 *
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