设置" SF UI显示粗体"作为标签字体

时间:2015-11-01 08:59:50

标签: ios swift fonts ios9

我将标签的字体设置为SF UI Display Bold时出现问题。

我不想设置这种持久性,只有当布尔值为假时。

if (value.messageReaded == false) {
    cell.subjectLabel?.font = UIFont(name:"SF UI Display Bold", size: 17.0)
}

不幸的是,我的方法是不使用这种字体。

你是否有人知道" SF UI Display Bold"的正确标题。 swift中的字体?

谢谢!

2 个答案:

答案 0 :(得分:40)

理论上,您可以通过直接调用其字体名称来使用该字体。该字体的字体名称为.SFUIDisplay-Bold

然而,Apple不鼓励采用这种方法,并表示这些字体名称是私密的,并且可能随时更改。

使用旧金山字体的官方方式是致电systemFont,它会自动为您提供旧金山字体:

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)

有大量的字体粗细可供选择:

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

答案 1 :(得分:1)

根据Joern为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)

另见Apple Documentation