-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from wordpress-mobile/issue/newyork-serif-font
Adds a new method to use the iOS 13+ system serif (New York) font
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Foundation | ||
|
||
/// WPStyleGuide Extension to use serif fonts. | ||
/// | ||
extension WPStyleGuide { | ||
/// Returns the system serif font (New York) for iOS 13+ but defaults to noto for older os's | ||
@objc public class func serifFontForTextStyle(_ style: UIFont.TextStyle, | ||
fontWeight weight: UIFont.Weight = .regular) -> UIFont { | ||
guard #available(iOS 13, *), | ||
let fontDescriptor = WPStyleGuide.fontForTextStyle(style, fontWeight: weight).fontDescriptor.withDesign(.serif) | ||
else { | ||
return WPStyleGuide.notoFontForTextStyle(style, fontWeight: weight) | ||
} | ||
|
||
return UIFontMetrics.default.scaledFont(for: UIFont(descriptor: fontDescriptor, size: 0.0)) | ||
} | ||
|
||
|
||
private class func notoFontForTextStyle(_ style: UIFont.TextStyle, | ||
fontWeight weight: UIFont.Weight = .regular) -> UIFont { | ||
var font: UIFont | ||
|
||
switch weight { | ||
// Map all the bold weights to the bold font | ||
case .bold, .semibold, .heavy, .black: | ||
font = WPStyleGuide.notoBoldFontForTextStyle(style) | ||
default: | ||
font = WPStyleGuide.notoFontForTextStyle(style) | ||
} | ||
|
||
return font | ||
} | ||
} |