开发者

Fonts not displaying in Interface Builder

开发者 https://www.devze.com 2023-01-09 21:25 出处:网络
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

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


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消