简体   繁体   English

iOS在界面构建器中设置自定义字体在设备上不起作用

[英]iOS setting custom font in interface builder does not work on device

I followed this step by step and successfully added a custom font in my project, I am able to change the font of my textView by setting my textView's font attribute programmatically. 我逐步进行了步骤,并成功在项目中添加了自定义字体,通过编程设置我的textView的font属性,可以更改textView的font

In interface builder, I can also set the custom font using the font picker for my textView, and I can see that the font is applied to the textView in interface builder. 在界面构建器中,我还可以使用字体选择器为textView设置自定义字体,并且可以看到该字体已应用于界面构建器中的textView。

The problem is if I remove the code that sets the font, then the font on real device is still the system font despite that I already set the font in interface builder. 问题是,如果我删除了设置字体的代码,那么尽管我已经在界面生成器中设置了字体,但实际设备上的字体仍是系统字体。

So how can I set the custom font in interface builder and make it work, without having to set the font in code? 那么,如何在界面生成器中设置自定义字体并使之工作,而不必在代码中设置字体呢?

Go to Build Phases --> Copy Bundle resources 转到构建阶段->复制捆绑包资源

see Your custom font file is there or not . 请参阅您的自定义字体文件是否存在。

It is not there then click on + sign and add it . 它不存在,然后单击+号并添加它。

Before that check that you add font file in your project . 在此之前,请检查是否在项目中添加了字体文件。

also check whether it is set in .plist file or not 还检查它是否在.plist文件中设置

I had the same problem, I deleted the fonts from my app and put them back by using group creation and not folder reference, so my fonts appeared in "Copy Bundle Resources". 我遇到了同样的问题,我从应用程序中删除了字体,然后通过使用组创建而不是文件夹引用将其放回去,因此我的字体出现在“复制捆绑资源”中。 Now it's working perfectly. 现在,它运行良好。

Steps which are done for Font is correct, but as per my understanding 2 things are there first is Xcode displays fonts which are found in the Mac OS or in your system, not on the actual iOS device. 对Font所做的步骤是正确的,但是据我了解,有两件事是Xcode显示在Mac OS或系统中找到的字体,而不是在实际的iOS设备上找到的字体。 Before selecting a font, you should make sure it is available on iOS devices. 选择字体之前,应确保它在iOS设备上可用。 and second is when we edit text in xib,custom Fonts appear, but at runtime it will not get applied. 其次是当我们在xib中编辑文本时,将显示自定义字体,但在运行时将不会应用。 So it is better that you apply font pragmatically. 因此,最好务实地应用字体。
http://iosfonts.com/ , http://support.apple.com/en-in/HT202771 or even trial and error can help. http://iosfonts.com/http://support.apple.com/en-in/HT202771甚至试错可以提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么Interface Builder中的“推断”设置不起作用? - Why does “inferred” setting in Interface Builder not work? 自定义字体在“界面生成器”中可见,但在iOS项目中的代码中则未 - Custom font seen in Interface builder but not in code in iOS project 将大小设置为自定义iOS字体不起作用 - Setting size to custom iOS font doesnt work iOS 8:界面构建器中设置的自定义选项卡栏项目的选定图像不起作用 - iOS 8: Selected image for custom tab bar item set in interface builder does not work iOS Interface Builder自定义样式? - iOS Interface Builder Custom Styles? 在Interface Builder中使用自定义字体放置UILabel - Positioning an UILabel with a custom font in Interface Builder iOS自定义字体显示在模拟器上,但不会在设备上显示 - iOS custom font shows on simulator, but does not show on device IOS中的自定义字体未在设备上反映 - Custom Font in IOS Not Reflected On Device 为什么我的自定义UITextField在Interface Builder上与在设备上运行时看起来有所不同? - Why does my custom UITextField look like different at Interface Builder vs in running on device? 在Interface Builder中,UIButton的动态类型“自动调整字体”设置等效? - Equivalent of dynamic type “automatically adjusts font” setting for UIButton in Interface Builder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM