Created
February 10, 2019 23:52
-
-
Save yfujiki/f2a9091e692337dc1cf0a6a02f649993 to your computer and use it in GitHub Desktop.
UILabel extension with regular/bold font that works
This file contains hidden or 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
| extension UILabel { | |
| @objc var substituteFontName: String { | |
| get { | |
| return font.fontName | |
| } | |
| set { | |
| // Set custom font unless the original font is a bold font. | |
| if font.fontName.range(of: "Medium") == nil { | |
| font = UIFont(name: newValue, size: font.pointSize) | |
| } | |
| } | |
| } | |
| @objc var substituteBoldFontName: String { | |
| get { | |
| return font.fontName | |
| } | |
| set { | |
| // Set custom font only if the original font is a bold font. | |
| if font.fontName.range(of: "Medium") != nil { | |
| font = UIFont(name: newValue, size: font.pointSize) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment