【问题标题】:Asking for San Francisco font in different size returns a Times New Roman variant on iOS 13.1在 iOS 13.1 上请求不同大小的 San Francisco 字体会返回 Times New Roman 变体
【发布时间】:2020-03-25 01:48:12
【问题描述】:

执行时:

let l = UILabel()
let f = l.font!
let f8 = UIFont(name: f.fontName, size: f.pointSize + 8)!
NSLog("\(f.fontName)")
NSLog("\(f8.fontName)")

日志输出:

.SFUI-Regular
TimesNewRomanPSMT

当我要求相同的字体但更大一点时,为什么我不再获得 San Francisco 变体?这是 iOS 的错误吗?

当我这样做时

let f8 = f.withSize(f.pointSize + 8)

我确实得到了 .SFUI-Regular。

【问题讨论】:

  • 我已经提交了一份错误报告,因为它是从 iOS 13 开始的问题。Apple 以“调查完成 - 按当前设计工作”关闭了它。

标签: ios swift fonts uikit


【解决方案1】:

使用f.familyName 而不是f.fontName

姓氏:https://developer.apple.com/documentation/uikit/uifont/1619033-familyname

字体名称:https://developer.apple.com/documentation/uikit/uifont/1619024-fontname

另外,init(name:size) 中的 fontName 必须包含全名,包括 familyName:https://developer.apple.com/documentation/uikit/uifont/1619041-init

【讨论】:

    猜你喜欢
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多