UIFont
有获得常规字体(systemFontOfSize
)或粗体字体(boldSystemFontOfSize
)的方法,但是如何通过storyboard获得“瘦系统字体”?
向UIFont
构造函数传递" system -thin“不起作用,这个构造函数只适用于非系统字体。
发布于 2015-08-02 20:02:48
你可以使用系统字体的粗细:
UIFont.systemFont(ofSize: 34, weight: UIFontWeightThin)
旧金山可用的权重列表:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
UIFontWeightBlack
从iOS 11开始, UIFontWeight*
已重命名为UIFont.Weight.*
。更多信息,请点击这里,https://developer.apple.com/documentation/uikit/uifont.weight。
发布于 2015-08-02 21:09:11
从iOS 8.2开始,您现在可以使用UIFont.systemFontOfSize(_ fontSize: CGFloat, weight weight: CGFloat)
UIFont.systemFontOfSize(19, weight: UIFontWeightLight)
iOS SDK提供了权重常量:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
当你想使用系统字体时,使用系统字体比基于字体名称创建字体更好,因为iOS可以在iOS上更改他们的系统字体(就像他们在iOS 7中对Helvetica Neue所做的那样,现在在iOS 9中,旧金山也是如此)。
所以我建议包括你想要的字体的文件,因为使用该TTF文件作为自定义字体,并在你的应用中使用自定义字体。
这就是我不喜欢苹果的特殊原因。苹果说什么,就不会 go。永远做我们想做的事。苹果一直在为每个操作系统改变的默认字体。
发布于 2017-05-01 01:47:35
另外,如果你想保持字体大小不变,只改变粗细,那么就使用目标元素的字体大小。例如:
demoLabel.font = UIFont.systemFont(ofSize: demoLabel.font.pointSize, weight: UIFontWeightThin)
有了这个,你可以保留默认的标签字体大小,只需改变粗细。
从iOS 11开始, UIFontWeightThin已重命名为UIFont.Weight.thin
。更多信息,请点击这里,https://developer.apple.com/documentation/uikit/uifont.weight。
https://stackoverflow.com/questions/31771679
复制相似问题