简体   繁体   English

字体未在Interface Builder中显示

[英]Fonts not displaying in Interface Builder

For some reason many of the fonts will not display in Interface Builder when I am designing my iPad app. 出于某种原因,在设计iPad应用程序时,许多字体都不会显示在Interface Builder中。 Unfortunately my iPad is yet to be delivered so I cannot tell if this is going to be a problem in the long run, but it certainly maintains through to the simulator. 不幸的是我的iPad还没有交付,所以我不知道从长远来看这是否会成为一个问题,但它肯定会维持到模拟器。

The fonts in question are listed on various websites as being compatible with the iPad but SDK 4.0.1 still seems to be confused. 有问题的字体在各种网站上列为与iPad兼容,但SDK 4.0.1似乎仍然很混乱。

For example Hoefler Text font assigned to a label drawn directly on fresh iPad view displays using the default font. 例如,分配给使用默认字体直接在新鲜iPad视图上显示的标签的Hoefler Text字体。 If I click to edit the text it displays in the correct font. 如果我单击编辑文本,它将以正确的字体显示。 I've tried it on a couple of macs now 我现在已经在几台Mac上试过了

This is a problem as I need to send through the app mock ups to my client to sign of the pixel perfect layouts for their backend team :( 这是一个问题,因为我需要通过应用程序模拟发送到我的客户端为他们的后端团队签署像素完美布局:(

Any ideas?! 有任何想法吗?!

For others who might be interested: there is a bug/known issue with IB on XCode 3.x with non-standard fonts and Interface Builder. 对于可能感兴趣的其他人:XCode 3.x上的IB存在一个错误/已知问题,包括非标准字体和Interface Builder。 Custom fonts generally need to be set programatically (via [UIFont fontWithName...). 自定义字体通常需要以编程方式设置(通过[UIFont fontWithName ...)。

For mockups you should use a tool like PhotoShop, etc rather than Interface Builder. 对于模型,您应该使用PhotoShop等工具而不是Interface Builder。

using custom fonts in Interface Builder a reusable library is available. 在Interface Builder中使用自定义字体,可以使用可重用的库。

It uses a simple trick for doing this. 它使用一个简单的技巧来做到这一点。 Set the font(say calibri) to all of your UI Elements that you will never use in your project and FontReplacer will do mapping between custom font and calibri. 将字体(比如calibri)设置为您在项目中永远不会使用的所有UI元素,FontReplacer将在自定义字体和calibri之间进行映射。 So there is no need to make IBOutlets or any other graphics. 所以不需要制作IBOutlets或任何其他图形。

Here is link to github from where you can download FontReplacer to use in your project. 这里是github的链接,您可以从中下载FontReplacer以在项目中使用。 https://github.com/0xced/FontReplacer https://github.com/0xced/FontReplacer

I solved this by writing a custom category on UILabel. 我通过在UILabel上编写自定义类别来解决这个问题。 That category has a 'myFontName' property that I set on the label using objc_setAssociatedObject, and get from the object using objc_getAssociatedObject. 该类别有一个'myFontName'属性,我使用objc_setAssociatedObject在标签上设置,并使用objc_getAssociatedObject从对象获取。

I then wrote another method in the category called 'updateWithMyFont' that sets the font on the label via the label's attributed text property ( grab the attributedText and copy the attributes, set the font, create a new attributed string, set the attributedText property). 然后,我在名为“updateWithMyFont”的类别中编写了另一种方法,通过标签的属性文本属性设置标签上的字体(获取attributesText并复制属性,设置字体,创建新的属性字符串,设置attributedText属性)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM