6

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?

leviathan
  • 11,080
  • 5
  • 42
  • 40
vivianaranha
  • 2,781
  • 6
  • 33
  • 47

6 Answers6

4

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

leviathan
  • 11,080
  • 5
  • 42
  • 40
  • 2
    Pixate has, by far, been the simplest way to handle custom type in my app. There is so much less code involved to do simple things. I love it. – Clifton Labrum Jan 13 '14 at 20:36
2

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];
coneybeare
  • 33,113
  • 21
  • 131
  • 183
2

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?

Josh Bleecher Snyder
  • 8,262
  • 3
  • 35
  • 37
2

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
mxcl
  • 26,392
  • 12
  • 99
  • 98
1

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

Tim
  • 59,527
  • 19
  • 156
  • 165
  • 1
    Then is there somethign called as APplication font that I can use.... Coz i dotn wnat to individually assign font to every thing i have on the app... So is there a way i can define a font and then it will be used throught teh app – vivianaranha Nov 10 '09 at 18:41
0

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.

Ben S
  • 68,394
  • 30
  • 171
  • 212