Fonts not displaying in Interface Builder

痞子三分冷 提交于 2019-12-17 16:11:34

问题


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.

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.

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

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?!


回答1:


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...).

For mockups you should use a tool like PhotoShop, etc rather than Interface Builder.




回答2:


using custom fonts in Interface Builder a reusable library is available.

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.

Here is link to github from where you can download FontReplacer to use in your project. https://github.com/0xced/FontReplacer




回答3:


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.

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).



来源:https://stackoverflow.com/questions/3398693/fonts-not-displaying-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!