首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UIFont -如何获得系统瘦字体

UIFont -如何获得系统瘦字体
EN

Stack Overflow用户
提问于 2015-08-02 19:57:24
回答 4查看 58.2K关注 0票数 103

UIFont有获得常规字体(systemFontOfSize)或粗体字体(boldSystemFontOfSize)的方法,但是如何通过storyboard获得“瘦系统字体”?

UIFont构造函数传递" system -thin“不起作用,这个构造函数只适用于非系统字体。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-08-02 20:02:48

你可以使用系统字体的粗细:

代码语言:javascript
复制
UIFont.systemFont(ofSize: 34, weight: UIFontWeightThin)

旧金山可用的权重列表:

代码语言:javascript
复制
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
UIFontWeightBlack

从iOS 11开始, UIFontWeight*已重命名为UIFont.Weight.*。更多信息,请点击这里,https://developer.apple.com/documentation/uikit/uifont.weight

票数 272
EN

Stack Overflow用户

发布于 2015-08-02 21:09:11

从iOS 8.2开始,您现在可以使用UIFont.systemFontOfSize(_ fontSize: CGFloat, weight weight: CGFloat)

UIFont.systemFontOfSize(19, weight: UIFontWeightLight)

iOS SDK提供了权重常量:

代码语言:javascript
复制
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy

当你想使用系统字体时,使用系统字体比基于字体名称创建字体更好,因为iOS可以在iOS上更改他们的系统字体(就像他们在iOS 7中对Helvetica Neue所做的那样,现在在iOS 9中,旧金山也是如此)。

所以我建议包括你想要的字体的文件,因为使用该TTF文件作为自定义字体,并在你的应用中使用自定义字体。

这就是我不喜欢苹果的特殊原因。苹果说什么,就不会 go。永远做我们想做的事。苹果一直在为每个操作系统改变的默认字体。

票数 32
EN

Stack Overflow用户

发布于 2017-05-01 01:47:35

另外,如果你想保持字体大小不变,只改变粗细,那么就使用目标元素的字体大小。例如:

代码语言:javascript
复制
demoLabel.font = UIFont.systemFont(ofSize: demoLabel.font.pointSize, weight: UIFontWeightThin)

有了这个,你可以保留默认的标签字体大小,只需改变粗细。

从iOS 11开始, UIFontWeightThin已重命名为UIFont.Weight.thin。更多信息,请点击这里,https://developer.apple.com/documentation/uikit/uifont.weight

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31771679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档