Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom fonts in interface builder

I've searched this site but I just found unanswered questions.

I've loaded a custom font into my xcode project. A [UIFont fontWithName:@"Laconic-Light" size:19] works. But interface builder doesn't like the font. I can't use it with IB it always shows the default font. Is there a way to tell IB that its ok to use the font?

like image 247
david Avatar asked Nov 26 '10 11:11

david


People also ask

How do I use custom fonts in Xcode 13?

Add the font file to your Xcode projectSelect File menu > Add Files to "Your Project Name"... from the menu bar, select all the fonts you need to add, then click the Add button. Or drag the file from Finder and drop it into your Xcode project. Drag the font files from Finder and drop it into your Xcode project.


2 Answers

I have also this problem in Xcode 4. In my program, there are lots of UILabel which have no IBOutlets so I do in that way;

First, subclass the UILabel to CustomFontLabel

Then, override the "awakeFromNib" method

@implementation CustomFontLabel  - (void)awakeFromNib {     [super awakeFromNib];     self.font = [UIFont fontWithName:@"CustomFontName" size:self.font.pointSize]; }  @end 

Finally, in Interface Builder > Identity Inspector change class to CustomFontLabel.

like image 136
Atif Avatar answered Oct 03 '22 02:10

Atif


Another solution would be to subclass UILabel to load in your custom font. You can then reference it in IB, although you still cannot see the proper font.

like image 29
James Hall Avatar answered Oct 03 '22 01:10

James Hall