51

So we're in 2014, is there any way to set custom fonts within Interface Builder yet? Ie don't do it programmatically, except for "Fonts provided by application" in the app's plist.

Jonny
  • 15,955
  • 18
  • 111
  • 232
  • http://stackoverflow.com/questions/9683929/designing-labels-text-views-with-custom-fonts-in-interface-builder – codercat Feb 26 '14 at 09:23
  • May be the same question as follow: + [Designing labels/text views with custom fonts in Interface Builder](http://stackoverflow.com/questions/9683929/designing-labels-text-views-with-custom-fonts-in-interface-builder/27339161#27339161) + [Custom font in a storyboard?](http://stackoverflow.com/questions/9090745/custom-font-in-a-storyboard/) May it be helpful. – monjer Dec 07 '14 at 03:12

5 Answers5

72

Yes, Marrius is right. In Xcode 6, you neither need to use extra software nor to set Font in Code files. Just add your font files in your project along with other files. And Interface builder will display the added fonts in the Custom Font List.

And the most amazing thing is, xcode 6 shows the applied font instantly in IB. This is the great addition by Apple.

Also make sure to add this key "Fonts provided by application" in your project's info.plist and provide your font file names to see the effect in devices.

Asif Bilal
  • 4,309
  • 3
  • 17
  • 27
  • 11
    Yeah, but for some reason after adding the fonts to the project and setting the label's font in interface builder – the font doesn't show up on device. Looks just fine in IB though.. – Nima Gardideh Jun 18 '14 at 01:46
  • 5
    You're right. One thing more you should do. In your Project's Info.plist, you must add this key "Fonts provided by application". And provide your font file names. That would do work for the devices.This is the way the application would know that these fonts should be included in application's bundle. – Asif Bilal Jun 19 '14 at 04:45
  • 11
    But only if it's not an attributed string. At least not with FontAwesome nor Open Sans. – Fábio Oliveira Sep 10 '14 at 20:31
  • 1
    @FábioOliveira indeed, doesn't seem to work the attributed string. – Jkmn Sep 18 '14 at 12:43
  • 4
    Wow. What a "great addition" by Apple after more than 6 years of XCode being around for iOS... Sorry, I love XCode but this was just unnecessary torture for a long time. And the fact that it's still not working with Attributed Strings is just ridiculous. – gchbib Dec 02 '14 at 13:56
  • 2
    But its really not reliable. I have added Open Sans font in my project and added the entries in info.plist file. Still the font is showing in custom fonts list for one xib but not for others. – Ans Feb 08 '15 at 16:28
  • 1
    @AsifBilal There was an additional step to make this work for me – had to manually add the attached font file(s) to the "Copy Bundle Resources" build phase, since XCode doesn't seem to do so automatically like with other files. – canfan Jun 01 '15 at 20:09
14

In Xcode 6, we have custom fonts available in interface builder.

No need for extra software. Thank you Apple!

Marius Popescu
  • 453
  • 3
  • 11
  • 4
    Yeah, but for some reason after adding the fonts to the project and setting the label's font in interface builder – the font doesn't show up on device. Looks just fine in IB though.. – Nima Gardideh Jun 18 '14 at 01:48
  • @NimaGardideh, isn't that the case for attributed text? I'm having the same. – Fábio Oliveira Sep 10 '14 at 20:31
  • I recall it not working for attributed text as well. Though, I think the problem fixed itself in one of the later betas. – Nima Gardideh Sep 12 '14 at 22:22
  • 1
    But its really not reliable. I have added Open Sans font in my project and added the entries in info.plist file. Still the font is showing in custom fonts list for one xib but not for others. – Ans Feb 08 '15 at 16:29
9

In Xcode 6, just add the ttf file in your project and use it in storyboard through custom fonts. If you directly want to use it in your code without using it in storyboard then you have to add key "UIAppFonts" in projectName-Info.plist.

Example:

<key>UIAppFonts</key> 
<array>
    <string>Signika-Bold.ttf</string>
    <string>Signika-Regular.ttf</string>
    <string>Signika-Light.ttf</string>
    <string>Signika-Semibold.ttf</string>
</array> 

just before the line </dict> in projectName-Info.plist.

UIFont* font  = [UIFont fontWithName:@"Signika-Regular" size:25];
Brian
  • 14,610
  • 7
  • 35
  • 43
ankurkumar
  • 91
  • 1
  • 1
1

Looks like someone worked on it. You can have a look at MoarFonts :

MoarFonts

Use custom fonts for your iOS projects directly in Interface Builder, the WYSIWYG way

by Cédric Luthi “0xced

It costs 10$, but :

Since iOS 3.2, you can use custom fonts in your iOS apps by adding the UIAppFonts Info.plist key. Unfortunately, custom fonts are not available when editing your xib files in Interface Builder. MoarFonts makes your custom fonts available right within Interface Builder.

MoarFonts is compatible with both Xcode 4 and Xcode 5.

rdurand
  • 7,342
  • 3
  • 39
  • 72
1

This is my solution, nothing else worked for me

#import "UILabelEx.h"
#import "Constants.h"

@implementation UILabelEx

//- (void)layoutSubviews
//{
//    [super layoutSubviews];
//    // Implement font logic depending on screen size
//    self.font = [UIFont fontWithName:@"CustomFont" size:self.font.pointSize];
//}

- (void) traitCollectionDidChange: (UITraitCollection *) previousTraitCollection {
    [super traitCollectionDidChange: previousTraitCollection];

    self.font = [UIFont fontWithName:APP_FONT size:self.font.pointSize];
}
@end
Jules
  • 7,568
  • 14
  • 102
  • 186
  • Crazy that this was the only thing that worked for me too. My custom fonts are accessible from code just fine. In interface builder, they appear in the font menus and are selectable. They are rendered correctly in interface builder. But when actually running in the simulator, it's Helvetica-city. – Luke Bartolomeo Dec 08 '16 at 18:29
  • I think this is fixed in Xcode 8 but I haven't removed my code. – Jules Dec 08 '16 at 19:25