Skip to content

Commit c0e1cc0

Browse files
committed
Update custom font function to properly handle max font sizes
1 parent 11cca1d commit c0e1cc0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

WooCommerce/Classes/Extensions/UIFont+Helpers.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ extension UIFont {
8484
return UIFontMetrics(forTextStyle: style).scaledFont(for: noticonFont)
8585
}
8686

87-
/// Returns a UIFont instance for the specified Style + Weight.
87+
/// Returns a UIFont instance for the specified Style + Weight + Max Size.
8888
///
89-
class func font(forStyle style: UIFont.TextStyle, weight: UIFont.Weight) -> UIFont {
89+
class func font(forStyle style: UIFont.TextStyle, weight: UIFont.Weight, maxFontSize: CGFloat? = nil) -> UIFont {
9090
let descriptor = UIFontDescriptor
9191
.preferredFontDescriptor(withTextStyle: style)
9292
.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: weight]])
93+
94+
// Limit the font size if needed
95+
if let maxFontSize, descriptor.pointSize > maxFontSize {
96+
return UIFont(descriptor: descriptor, size: maxFontSize)
97+
}
98+
99+
// Return font without a predefined size.
93100
return UIFont(descriptor: descriptor, size: 0)
94101
}
95102

0 commit comments

Comments
 (0)