Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set "SF UI Display Bold" as label font

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!

like image 646
SebThePalm Avatar asked Nov 01 '15 08:11

SebThePalm


2 Answers

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
like image 75
joern Avatar answered Nov 08 '22 08:11

joern


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

like image 29
Chris Herbst Avatar answered Nov 08 '22 08:11

Chris Herbst