8

As I understand all standard controls use system font by default.

Also, API [UIFont systemFontOfSize: ] uses system font too.

Is there a way to redefine it for the whole application, instead of setting a font for table, labels and so on?

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184

2 Answers2

10

The answer is no, you cant change apple's systemFont, you need to set the font on your control yourself.

For best way to set a default font for whole iOS app, please check the below SO questions:

Set a default font for whole iOS app?

How to set a custom font for entire iOS app without specifying size

How do I set a custom font for the whole application?

Is there a simple way to set a default font for the whole app?

Community
  • 1
  • 1
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
5

Define and export (by including a header in files or in precompiled header) a category of UIFont as following:

@implementation UIFont (Utils)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

+ (UIFont *)systemFontOfSize:(CGFloat)size
{
    return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}

+ (UIFont *)lightSystemFontOfSize:(CGFloat)size
{
    return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}

+ (UIFont *)boldSystemFontOfSize:(CGFloat)size
{
    return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}

+ (UIFont *)preferredFontForTextStyle:(NSString *)style
{
    if ([style isEqualToString:UIFontTextStyleBody])
        return [UIFont systemFontOfSize:17];
    if ([style isEqualToString:UIFontTextStyleHeadline])
        return [UIFont boldSystemFontOfSize:17];
    if ([style isEqualToString:UIFontTextStyleSubheadline])
        return [UIFont systemFontOfSize:15];
    if ([style isEqualToString:UIFontTextStyleFootnote])
        return [UIFont systemFontOfSize:13];
    if ([style isEqualToString:UIFontTextStyleCaption1])
        return [UIFont systemFontOfSize:12];
    if ([style isEqualToString:UIFontTextStyleCaption2])
        return [UIFont systemFontOfSize:11];
    return [UIFont systemFontOfSize:17];
}

#pragma clang diagnostic pop

@end

Light variant comes as a useful extra starting with iOS 7. Enjoy! ;)

Michi
  • 1,464
  • 12
  • 15
  • @orj Why is this not a good idea ? this doesn't seem to be using a undocumented api's . or is it ? – Kiran Ruth R Aug 26 '15 at 06:42
  • 2
    Well, it overloads standard implementation of these methods in UIKit, which is not completely recommended; f.e. iOS 9 comes with adaptive switching of system font between San Francisco _Display_ and _Text_ variants depending on a requested font size. I still found this technique **safe** though, unless you are writing a typographic app or need some font extras, this is very easy and quick way to switch default app fonts in a pretty deterministic way. – Michi Aug 26 '15 at 13:42