Thursday, January 19, 2012

How to Set the "tintColor" of the Back Button for Popovers in iOS5

I am developing an iPad application. After customizing the popover background by setting it red, I tried to set the "tintColor" of the "Back" button on the popover navigation bar. Otherwise, it looks ugly!



As I am developing the application in iOS5, the new appearance protocol makes customization very easy:


- (void)customizeAppearance
{
    // set the back button tint color
    [[UIBarButtonItem appearance] setTintColor: [UIColor redColor]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
    DBG_CALLED
    
    [self customizeAppearance];

    return YES;
}

Note that DBG_CALLED is my debug macro. However, in this case the update is global and the buttons on the toolbar are updated also which is not what I want!




The solution is specifying where to update the bar button items:


- (void)customizeAppearance
{
    // set the back button tint color for the popovers
    [[UIBarButtonItem appearanceWhenContainedIn:[UIPopoverController class], nil] 
                                   setTintColor:[UIColor redColor]];
}

The end result is what I want exactly:


I love the iOS5!


No comments: