如何在 iOS 9 中使用新的 San Francisco 字体? [英] How to use new San Francisco font in iOS 9?

查看:64
本文介绍了如何在 iOS 9 中使用新的 San Francisco 字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 9 之前,我们使用 UIFontfontWithName 来引用字体:

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?

我们可以和UIFontsystemFontOfSize一起使用,但是如何引用普通样式以外的样式呢?例如,如何使用 San Francisco MediumSan 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆