如何在 iOS 9 中使用新的 San Francisco 字体? [英] How to use new San Francisco font in iOS 9?
问题描述
在 iOS 9 之前,我们使用 UIFont
的 fontWithName
来引用字体:
Before iOS 9 to reference fonts we used fontWithName
of UIFont
:
[UIFont fontWithName:@"HelveticaNeue" size:18]
现在我们要迁移到 iOS 9.如何以同样的方式引用新的 San Francisco 字体?
Now we're moving to iOS 9. How to reference a new San Francisco font in the same way?
我们可以和UIFont
的systemFontOfSize
一起使用,但是如何引用普通样式以外的样式呢?例如,如何使用 San Francisco Medium 或 San Francisco Light 字体?
We can use it with systemFontOfSize
of UIFont
, but how to reference styles other than regular? For example, how to use San Francisco Medium or San Francisco Light fonts?
推荐答案
在 iOS 9 中它是系统字体,所以你可以这样做:
In iOS 9 it is the system font, so you could do:
let font = UIFont.systemFontOfSize(18)
你可以直接使用字体名称,但我认为这不安全:
You can use the font name directly, but I don't think this is safe:
let font = UIFont(name: ".SFUIText-Medium", size: 18)!
您还可以使用 比重,像这样:
You can also create the font with specific weight, like so:
let font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium)
或
let font = UIFont.systemFontOfSize(18, weight: UIFontWeightLight)
这篇关于如何在 iOS 9 中使用新的 San Francisco 字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!