How to use new San Francisco font in iOS 9?

2019-03-09 06:23发布

Before iOS 9 to reference fonts we used fontWithName of UIFont:

[UIFont fontWithName:@"HelveticaNeue" size:18]

Now we're moving to iOS 9. How to reference a new San Francisco font in the same way?

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 fonts ios9
2条回答
做个烂人
2楼-- · 2019-03-09 07:01

Swift 4

label.font = UIFont.systemFont(ofSize: 22, weight: UIFont.Weight.bold)
查看更多
Viruses.
3楼-- · 2019-03-09 07:17

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)

or

let font = UIFont.systemFontOfSize(18, weight: UIFontWeightLight)
查看更多
登录 后发表回答