UINavigationBar customization under iOS 5 problem

Apple changed the rules with iOS 5 and UINavigationBar customization. Apple now required to do drawRect when subclassing the UINavigationBar instead of implementing a protocol as it was done under iOS 4. See this question on StackOverflow.

I'm putting the final touch to the next release of Ultimate Password Manager but I found out that doing the UINavigationBar customization only works partially. The Apple's proposed way like shown in this small tutorial  is very simple: http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/. Here is my UINavigationBar subclassing. 
//
//  MyCustomNavigationBar.h
//  uPasswords
//
//  Created by Martin Jean-François on 11-11-09.
//  Copyright (c) 2011 TinySofty. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyCustomNavigationBar : UINavigationBar

@end

#import "MyCustomNavigationBar.h"

@implementation MyCustomNavigationBar

- (void)drawRect:(CGRect)rect {
    UIImage *backgroundImage = [UIImage imageNamed:@"NavigationTitleBackground.png"];
CGContextDrawImage(UIGraphicsGetCurrentContext(),
  CGRectMake(0, 0, self.frame.size.width
                                                            self.frame.size.height),
  backgroundImage.CGImage);
}

@end

In Interface Builder, I made the change to all the UINavigation object properties to change it to my newly defined subclass like shown in the following screen shot. 
The solution is working fine. Mostly. My problem is simple. My application is using a Tabbar with nine (9) tabs. The UINavigationBar is effectively customized for the first four (4) only! So it seems that for the "More" tab and the following one, the subclass's method is not being called so the customization isn't done. Why?

0 comments:

Post a Comment