Question

I am trying to globally set the styling of my UINavigationBar titles. I have had success using the appearance object with many of the UI controls but for some reason these titles will not change... I am trying to set the font, font color and size but neither are working. My code is below.

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
                                                                       appFontOfSize:24], NSFontAttributeName,
                            [UIColor whiteColor], NSForegroundColorAttributeName, nil];

[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Était-ce utile?

La solution

I did something similar in my app (IOS 7). I used the following code:

NSDictionary * navBarTitleTextAttributes = @{ NSForegroundColorAttributeName : [UIColor whiteColor],
                                              NSFontAttributeName: [UIFont systemFontOfSize:18.0f]
                                              };

[[UINavigationBar appearance] setTitleTextAttributes:navBarTitleTextAttributes];

Actually it is pretty much the same code just with a different notation. But maybe it is working that way? Where do you set the appearance? I define it directly in the AppDelegate class.

Autres conseils

The code I'm using on iOS 6 and 7 is:

    [appearance setTitleTextAttributes:@{
                                         UITextAttributeTextColor : [UIColor blackColor],
                                         UITextAttributeTextShadowColor : [UIColor lightGrayColor],
                                         }];

Note the usage of UITextAttribute*

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top