如何在Swift中将文本字体设置为System Thin?

Ork*_*ade 8 fonts ios programmatically-created swift

我想将标签文本设置为System Thin.读入StackOverflow并找到如下答案:

labelDescriptionView.font = UIFont(name: "System-Thin", size: 15.0)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.如何以编程方式改进代码并制作Thin字体样式?

rck*_*nes 26

system在Interface Builder中的字体是操作系统默认字体,它不是一种字体,你可以通过它的名字获得.对于系统字体,Apple提供以下方法:

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
Run Code Online (Sandbox Code Playgroud)

这些不包括任何薄版本,但你可以使用iso 8.2你可以使用:

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight;
Run Code Online (Sandbox Code Playgroud)

你可以通过的地方:作为权重:

UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
Run Code Online (Sandbox Code Playgroud)

所以一个瘦的系统字体将是:

UIFont *thinFont = [UIFont systemFontOfSize:15 weight:UIFontWeightThin];
Run Code Online (Sandbox Code Playgroud)


uje*_*ell 13

如果你使用的是iOS 8.2或更高版本,你可以使用它;

label.font = UIFont.systemFontOfSize(15, weight: UIFontWeightThin)
Run Code Online (Sandbox Code Playgroud)

对于以前的版本,只需使用HelveticaNeue-Thin您的字体.