xcode 字体未显示在界面生成器中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3398693/
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
Fonts not displaying in Interface Builder
提问by Anthony Main
For some reason many of the fonts will not display in Interface Builder when I am designing my iPad app. 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 应用程序时,Interface Builder 中不会显示许多字体。不幸的是,我的 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. If I click to edit the text it displays in the correct font. I've tried it on a couple of macs now
例如,分配给直接在新 iPad 视图上绘制的标签的 Hoefler Text 字体使用默认字体显示。如果我单击以编辑文本,它会以正确的字体显示。我现在已经在几台 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?!
有任何想法吗?!
回答by lxt
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. Custom fonts generally need to be set programatically (via [UIFont fontWithName...).
对于可能感兴趣的其他人:使用非标准字体和界面生成器的 XCode 3.x 上的 IB 存在错误/已知问题。自定义字体通常需要以编程方式设置(通过 [UIFont fontWithName...)。
For mockups you should use a tool like PhotoShop, etc rather than Interface Builder.
对于模型,您应该使用 PhotoShop 等工具而不是 Interface Builder。
回答by abdus.me
using custom fonts in Interface Buildera 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. So there is no need to make IBOutlets or any other graphics.
它使用一个简单的技巧来做到这一点。将字体(比如 calibri)设置为您永远不会在项目中使用的所有 UI 元素,FontReplacer 将在自定义字体和 calibri 之间进行映射。所以没有必要制作IBOutlets或任何其他图形。
Here is link to github from where you can download FontReplacer to use in your project. https://github.com/0xced/FontReplacer
这是 github 的链接,您可以从那里下载 FontReplacer 以在您的项目中使用。 https://github.com/0xced/FontReplacer
回答by Mark Pauley
I solved this by writing a custom category on UILabel. That category has a 'myFontName' property that I set on the label using objc_setAssociatedObject, and get from the object using objc_getAssociatedObject.
我通过在 UILabel 上编写自定义类别解决了这个问题。该类别具有我使用 objc_setAssociatedObject 在标签上设置的“myFontName”属性,并使用 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”的类别中编写了另一种方法,该方法通过标签的属性文本属性设置标签上的字体(获取属性文本并复制属性、设置字体、创建新的属性字符串、设置属性文本属性)。