Question

Is there a way I can change the System Font for an entire Application?

I want to define the font for the entire Application so that I don't have to go to individual labels or individual fonts to change it. I would like a universal definition which will change all the fonts that exist within the application. How do I do this?

Was it helpful?

Solution

Make a shared class called Constants.h or something. In it do this:

#define kStandardFont [UIFont systemFontOfSize:20] 

Of course adjust the font to be what you need it to be. Then, whenever you need to use it (in a label or whatever) do this:

#import "Constants.h"
…
…
… 
[label setFont:kStandardFont];

OTHER TIPS

You can use Pixate to style your app. When using pixate, you can set the style attributes of your UI elements via CSS. This way you can globally setup your UILabels and UITextField etc. to use your custom font. This is by far the best way to globally style your font.

In my app I had to use "Open Sans" and setup all my UILabels, UITextFields and UITextViews to use that font:

In your "default.css"

label {
    font-family: "Open Sans";
}

text-field {
    font-family: "Open Sans";
}

text-view {
    font-family: "Open Sans";
}

enter image description here

I think that the right answer is: Don't do that! Figure out why you think you want to do that, and then figure out some other way to achieve the same ends. And folks here would be happy to help figure out another way to those ends. (E.g. that's what coneybeare's answer effectively suggests.)

All that said...there's no way in the official SDK to change the system font. You might be able to make some headway by swizzling UIFont's systemFontWithSize: method -- see http://www.cocoadev.com/index.pl?MethodSwizzling for more on method swizzling. Bear in mind (a) this will only change the appearance of anything that uses systemFontWithSize: to get its font, (b) this might break all kinds of things that depend on the having the original font size, and (c) this might well get you rejected from the App Store.

All these caveats add up to the question: What are you really trying to accomplish with this?

Seems to work at least for UILabels:

@interface UIFont (mxcl)
@end
@implementation UIFont (mxcl)
+ (id)systemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter" size:sz]
}
+ (id)boldSystemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter-Bold" size:x]
}
@end

No - that's why it's called the system font, and not the application font.

Fonts are specific to each control in the UI. For exmaple, each UILabel has its own font setting.

If you want to change the font of all controls, you'll have to change them all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top