【问题标题】:Set "SF UI Display Bold" as label font将“SF UI Display Bold”设置为标签字体
【发布时间】:2016-02-01 07:58:49
【问题描述】:

我在将标签字体设置为 SF UI Display Bold 时遇到问题。

我不想设置这个持久化,只有当布尔值是假的时候。

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

很遗憾,我的方法不适用于这种字体。

你们中有人知道swift中“SF UI Display Bold”字体的正确标题吗?

谢谢!

【问题讨论】:

  • SF 的显示变体用于文本的大显示。不适用于 iPhone 标签。

标签: ios swift fonts ios9


【解决方案1】:

理论上,您可以通过直接调用字体名称来使用该字体。该字体的字体名称是.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

【讨论】:

  • 值得注意的是,系统会根据您要求的磅值自动为您选择显示或文本变体。根据 WWDC 演示,如果您请求大小 = 20 的系统字体,您将获得 Display 变体。
  • 对于小于 20 的字体大小,是否有任何非 hacky 的方式来获得“SF UI Display”?
【解决方案2】:

根据 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

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2017-07-31
    • 2020-07-07
    • 1970-01-01
    相关资源
    最近更新 更多