Reputation: 23268
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?
Upvotes: 8
Views: 19065
Reputation: 1484
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! ;)
Upvotes: 5
Reputation: 18470
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?
Upvotes: 10