[英]Custom font seen in Interface builder but not in code in iOS project
I added a custom font called "Quicksand_Dash.otf", "Quicksand-Bold.otf" to an iOS project. 我在iOS项目中添加了自定义字体“ Quicksand_Dash.otf”,“ Quicksand-Bold.otf”。 I can see it in Interface builder but can't see when I list fonts in code.
我可以在“界面生成器”中看到它,但是当我在代码中列出字体时看不到它。
"Fonts provided by application" and relevant name added to plist file. plist文件中添加了“应用程序提供的字体”和相关名称。
I checked If font file is in copy bundle resources. 我检查字体文件是否在副本包资源中。
How I list the font; 我如何列出字体;
for family in UIFont.familyNames {
let sName: String = family as String
print("family: \(sName)")
for name in UIFont.fontNames(forFamilyName: sName) {
print("name: \(name as String)")
}
}
I checked probably every answer in stack overflow but I think I have a different problem. 我检查了堆栈溢出中的每个答案,但我认为我遇到了另一个问题。
How To Use Custom Fonts in iPhone SDK 如何在iPhone SDK中使用自定义字体
Custom Fonts Not Working 自定义字体不起作用
EDIT: If I add a label in storyboard and make its font Quicksand. 编辑:如果我在情节提要中添加标签并使其字体为流沙。 Font is also listed in code.
字体也在代码中列出。 However, I don't wanna user storyboard.
但是,我不需要用户情节提要。 I'm creating controllers in code.
我正在用代码创建控制器。
EDIT2: If I delete label in storyboard. EDIT2:如果我删除情节提要中的标签。 It started to not seen again.
它开始不再被看到。
This is the same problem I'm facing but I applied the solutions in that post already; 这是我面临的相同问题,但是我已经在该文章中应用了解决方案。
Custom Font only available in Interface Builder 自定义字体仅在Interface Builder中可用
You're going to kick yourself... 你要踢自己...
In your plist info file, you have: 在您的plist信息文件中,您具有:
`Quicksand-Dash.otf`
but the file you added is named: 但是您添加的文件名为:
`Quicksand_Dash.otf`
underscore not hyphen 下划线不要连字符
Either rename your file, or edit the plist entry, and you'll see your font. 重命名文件,或编辑plist条目,您将看到字体。
Debug console output: 调试控制台输出:
family: Quicksand
name: Quicksand-BoldItalic
name: QuicksandDash-Regular
name: Quicksand-Bold
Here is a plain single-view project that works fine for me - on both Simulator and Device. 这是一个简单的单视图项目,在Simulator和Device上都对我有效。 (I have not added the fonts to OS X, only to my project):
(我没有将字体添加到OS X,仅添加到了我的项目中):
https://github.com/DonMag/Quicksand https://github.com/DonMag/Quicksand
Just for setup reference: 仅供安装参考:
I also stuck to this issue and given solutions don't work for me. 我也坚持这个问题,并且给出的解决方案对我不起作用。 In my case ttf file's "Target Membership" block is uncheck.
在我的情况下,ttf文件的“ Target Membership”块已取消选中。 So when I click on it, the respected ttf font listed in font family list.
因此,当我单击它时,字体家族列表中列出了受人尊敬的ttf字体。
Happy Coding!! 快乐编码!
From reference of @Donmag answer. 从@Donmag答案的参考。 I download his example project from GitHub and copy fonts from his project to my project then copy "Fonts provided by application" area from plist to my plist.
我从GitHub下载他的示例项目,并将字体从他的项目复制到我的项目,然后将plist的“应用程序提供的字体”区域复制到我的plist。 Interestingly, It copied as "UIAppFonts".
有趣的是,它被复制为“ UIAppFonts”。 However, It started to work now.
但是,它现在开始工作。
To use custom fonts in application 在应用程序中使用自定义字体
Check the below link for more reference. 检查以下链接以获取更多参考。
https://stackoverflow.com/a/28843547/9332509 https://stackoverflow.com/a/28843547/9332509
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.