-2

I'd like to use UIAppearance to set the size of the font of all the UIButtons in my app to 15, and the size of the font in all the UILabels in my app to 10. Here's what I have:

UIFont *dinMediumFont = [UIFont fontWithName:@"DINPro-Medium" size:15];
[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setFont:dinMediumFont];

UIFont *dinBoldFontBig = [UIFont fontWithName:@"DINPro-Bold" size:10];
[[UILabel appearanceWhenContainedIn:nil] setFont:dinBoldFontBig];

However, I'd like the font of the buttons in UINavigationBars to be smaller, I tried adding this:

UIFont *smallerFont =[UIFont fontWithName:@"DINPro-Medium" size:15];
[[UILabel appearanceWhenContainedIn:[UIButton class], [UINavigationBar class], nil] setFont:smallerFont];

but the font is staying as the default... Why could that be?

Eric
  • 16,003
  • 15
  • 87
  • 139

1 Answers1

0

Buttons in navigation bars aren't instances of UIButton nor any of its subclasses; instead they're instances of UIBarButtonItem.

UIBarButtonItem's text isn't actually a UILabel instance: instead of setting properties on UILabel's appearance-in-UIButton proxy, your second snippet will need to set the font property on UIBarButtonItem's appearance proxy.

rickster
  • 124,678
  • 26
  • 272
  • 326