@@ -11,22 +11,20 @@ final class StyleManager {
1111 }
1212
1313 static var statsFont : UIFont {
14- return self . fontForTextStyle ( . title3, weight: . semibold, maximumPointSize : 36.0 )
14+ return . font ( forStyle : . title3, weight: . semibold, maxFontSize : 36.0 )
1515 }
1616
1717 static var statsTitleFont : UIFont {
18- return self . fontForTextStyle ( . caption2, weight: . regular, maximumPointSize : maxFontSize)
18+ return . font ( forStyle : . caption2, weight: . regular, maxFontSize : maxFontSize)
1919 }
2020
2121 static var chartLabelFont : UIFont {
2222 // Dashboard chart needs from a slighly smaller maximum font to be able to fit it when using the biggest accessibility font.
23- return self . fontForTextStyle ( . caption2, weight: . regular, maximumPointSize : 20.0 )
23+ return . font ( forStyle : . caption2, weight: . regular, maxFontSize : 20.0 )
2424 }
2525
2626 static var headlineSemiBold : UIFont {
27- return self . fontForTextStyle ( . headline,
28- weight: . semibold,
29- maximumPointSize: maxFontSize)
27+ return . font( forStyle: . headline, weight: . semibold, maxFontSize: maxFontSize)
3028 }
3129
3230 static var subheadlineFont : UIFont {
@@ -38,21 +36,15 @@ final class StyleManager {
3836 }
3937
4038 static var subheadlineBoldFont : UIFont {
41- return self . fontForTextStyle ( . subheadline,
42- weight: . bold,
43- maximumPointSize: maxFontSize)
39+ return . font( forStyle: . subheadline, weight: . bold, maxFontSize: maxFontSize)
4440 }
4541
4642 static var thinCaptionFont : UIFont {
47- return self . fontForTextStyle ( . caption1,
48- weight: . thin,
49- maximumPointSize: maxFontSize)
43+ return . font( forStyle: . caption1, weight: . thin, maxFontSize: maxFontSize)
5044 }
5145
5246 static var footerLabelFont : UIFont {
53- return self . fontForTextStyle ( . footnote,
54- weight: . regular,
55- maximumPointSize: maxFontSize)
47+ return . font( forStyle: . footnote, weight: . regular, maxFontSize: maxFontSize)
5648
5749 }
5850
@@ -66,23 +58,3 @@ final class StyleManager {
6658 return UIStatusBarStyle . lightContent
6759 }
6860}
69-
70-
71- // MARK: - Private convenience methods
72- private extension StyleManager {
73- class func fontForTextStyle( _ style: UIFont . TextStyle , weight: UIFont . Weight , maximumPointSize: CGFloat = maxFontSize) -> UIFont {
74- let traits = [ UIFontDescriptor . TraitKey. weight: weight]
75- var fontDescriptor = UIFontDescriptor . preferredFontDescriptor ( withTextStyle: style)
76- fontDescriptor = fontDescriptor. addingAttributes ( [ . traits: traits] )
77- let fontToGetSize = UIFont ( descriptor: fontDescriptor, size: CGFloat ( 0.0 ) )
78- return UIFontMetrics ( forTextStyle: style) . scaledFont ( for: fontToGetSize, maximumPointSize: maximumPointSize)
79- }
80-
81-
82- private class func fontDescriptor( _ style: UIFont . TextStyle , maximumPointSize: CGFloat = maxFontSize) -> UIFontDescriptor {
83- let fontDescriptor = UIFontDescriptor . preferredFontDescriptor ( withTextStyle: style)
84- let fontToGetSize = UIFont ( descriptor: fontDescriptor, size: CGFloat ( 0.0 ) )
85- let scaledFontSize = CGFloat . minimum ( fontToGetSize. pointSize, maximumPointSize)
86- return fontDescriptor. withSize ( scaledFontSize)
87- }
88- }
0 commit comments