ios SF UI Text-Light(New san francisco)字体不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32762434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SF UI Text-Light(New san francisco) font doesn't work
提问by Mathi Arasan
I am try to change font for a label but it's doesn't work font name:new New san francisco.
我正在尝试更改标签的字体,但它不起作用字体名称:new New san francisco。
Import that font into project and add in info.plist and this is my code
将该字体导入项目并添加 info.plist,这是我的代码
labelname.font = [UIFont fontWithName:@"SF UI Text-Light" size:12];
If I use that's work fine
如果我使用它工作正常
labelname.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
But New san francisco font doesn't work. I don't know what I miss :(
但是新的旧金山字体不起作用。我不知道我想念什么:(
回答by d.rozumeenko
That's happens because you use the wrong System name for the font. Try to use
发生这种情况是因为您为字体使用了错误的系统名称。尝试使用
labelname.font = [UIFont fontWithName:@"SFUIText-Light" size:12];
How to find System font names see here Adding custom fonts to iOS app finding their real names
如何查找系统字体名称请参见此处 将自定义字体添加到 iOS 应用程序中查找其真实名称
回答by newfun
I try to log the system font and find the font name is ".SFUIText-Light" ,so
我尝试记录系统字体并发现字体名称是“.SFUIText-Light”,所以
labelname.font = [UIFont fontWithName:@".SFUIText-Light" size:12];
this is work.
这是工作。
回答by newfun
Please use https://www.dropbox.com/s/dyw7kl0mtrftjix/San-Francisco-UI-and-COMPACT.zip?dl=0this link and download the .ttf instead of .otf file. i am sure you got the result, best of luck.
请使用https://www.dropbox.com/s/dyw7kl0mtrftjix/San-Francisco-UI-and-COMPACT.zip?dl=0此链接并下载 .ttf 而不是 .otf 文件。我相信你得到了结果,祝你好运。
回答by Doug Hill
Adding an update: you should be using the system font APIs in UIFont. For example:
添加更新:您应该在 UIFont 中使用系统字体 API。例如:
UIFont.systemFont(ofSize: 12, weight: .light)
Apple specifically tells developers to no longer rely on a font name or file system representation for the system font.
Apple 特别告诉开发人员不要再依赖系统字体的字体名称或文件系统表示。
As an aside, I made up a library for using many of the special features of the SF font in your app. Feel free to check it out: https://github.com/djfitz/SFFontFeatures
顺便说一句,我创建了一个库,用于在您的应用程序中使用 SF 字体的许多特殊功能。请随意查看:https: //github.com/djfitz/SFFontFeatures
回答by Markus
IMPORTANT, really.
重要的,真的。
Use this code, it is very, very useful. With it you can know the real name of the font.
使用此代码,它非常非常有用。有了它,您就可以知道字体的真实名称。
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName)
print("Font Names = [\(names)]")
}
I show you an example.
我给你举个例子。
The Font file (you must add it into your project, as any other file):
字体文件(您必须将其添加到您的项目中,就像任何其他文件一样):
The Font file name in "Info.plist" (exactly the same name with the file extension):
“Info.plist”中的字体文件名(与文件扩展名完全相同):
Finally, the output in the log Debug (created by the code)
最后在日志Debug中输出(由代码创建)
So, you can write this font name:
所以,你可以写这个字体名称:
headerLabel.font = UIFont(name:"SFProDisplay-Heavy", size:30)
Use this code. It has saved me time. It is very useful (I think)!
使用此代码。它节省了我的时间。这是非常有用的(我认为)!