Aug 19, 2010

(iPhone)How to customize UINavigationBar's background

UINavigationBar has 2 methods to change it's style, barStyle and tintColor, but neither could set a background image for UINavigationBar.

Here is a solution to do that, add following code in your app delegate implementation file (.m) :

@interface UINavigationBar (MyCustomNavBar)
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
    UIImage *barImage = [UIImage imageNamed:@"background_image.png"];
    [barImage drawInRect:rect];

And change the "background_image.png" to the image what you want. This add a category in all UINavationBar used in your application, and you will see a fancy UINavigationBar.

No comments: