In iOs4
i created a custom navigation bar using this snippet
#import "UINavigationBar+CustomImage.h"
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
// Drawing code
UIImage *image = [[UIImage imageNamed:@"header.png"] retain];
[image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];
[image release];
}
@end
and it is well for ios4 in my app. Now I want to run this in iOs5
and the problem is that the custom navigation bar doesn't appear the way I want.
Can any one help me to create a custom navigation bar for iOs5
.
You need to use the appearance proxy. But, make sure to check if respondsToSelector for iOS4. Leave your current method in place for iOS4 and it will work on both.
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
// set globablly for all UINavBars
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
// could optionally set for just this navBar
//[navBar setBackgroundImage:...
}
The same problem is mentioned here: UINavigationBar's drawRect is not called in iOS 5.0. Please check this may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With