I have a problem with setting the font of my label to SF UI Display Bold.
I don't wanna set this durable, only if a boolean is false.
if (value.messageReaded == false) {
cell.subjectLabel?.font = UIFont(name:"SF UI Display Bold", size: 17.0)
}
Unfortunately, my approach isn't working with this font.
Does somebody of you know the correct title of the "SF UI Display Bold" font in swift?
Thanks!
Theoretically you could use the font by calling its font name directly. The font name for that font is .SFUIDisplay-Bold
.
However Apple discourages this approach and says that these font names are private and subject to change at any time.
The official way to use the San Francisco fonts is to call systemFont
which automatically gives you the San Francisco font:
let font = UIFont.systemFont(ofSize: 17)
To get a lighter or bolder font you can request the font weight:
let mediumFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium)
let lightFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.light)
let boldFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
There is a ton of font weights to choose from:
UIFont.Weight.ultraLight
UIFont.Weight.thin
UIFont.Weight.light
UIFont.Weight.regular
UIFont.Weight.medium
UIFont.Weight.semibold
UIFont.Weight.bold
UIFont.Weight.heavy
UIFont.Weight.black
As per Joern's answer updated for Swift 4:
let font = UIFont.systemFont(ofSize: 17)
let mediumFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium)
let lightFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.light)
let boldFont = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
Also see Apple Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With