labelname.font = [UIFont fontWithName:@"SFUIText-Light" size:12];
我尝试记录系统字体,并发现字体名称为“.SFUIText-Light”,因此
labelname.font = [UIFont fontWithName:@".SFUIText-Light" size:12];
这是工作。
非常重要。
使用这段代码,它非常有用。通过它,您可以知道字体的真实名称。
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName)
print("Font Names = [\(names)]")
}
headerLabel.font = UIFont(name:"SFProDisplay-Heavy", size:30)
添加更新:你应该在UIFont中使用系统字体API。例如:
UIFont.systemFont(ofSize: 12, weight: .light)
苹果公司明确告诉开发者不再依赖字体名称或文件系统表示来使用系统字体。
顺带一提,我为在您的应用程序中使用SF字体的许多特殊功能创建了一个库。请随意查看: https://github.com/djfitz/SFFontFeatures
[UIFont fontWithName:@"SFUIText-Light"]
,消除它们之间的空格。 - DovahkiinSF UI Text-Light
is its font family, and font name is.SFUIText-Light
- DawnSong