Skip to content

Instantly share code, notes, and snippets.

@yfujiki
Created February 10, 2019 23:52
Show Gist options
  • Select an option

  • Save yfujiki/f2a9091e692337dc1cf0a6a02f649993 to your computer and use it in GitHub Desktop.

Select an option

Save yfujiki/f2a9091e692337dc1cf0a6a02f649993 to your computer and use it in GitHub Desktop.
UILabel extension with regular/bold font that works
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