UINavigationBars are UIView subclasses usually found within UINavigationControllers and most applications with full view tableview support. However, I have found a lot of different posts of numerous forums about people having difficulty adding a backgroundImage to their UINavigationBar.
The one line method to do so is:
Code:
[aNavigationBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"aImageName"]] autorelease] atIndex:0];
In response to the difficulty, I decided to create a UINavigationBar subclass called MKNavigationBar which easily allows the developer to add an image to their navigationBar, add a titleView with a different font and colour, and clear both the title and the image.
MKNavigationBar can be found here:
https://github.com/MaxKDevelopment/MKNavigationBar
Once you have downloaded it import it into your ViewController above the @implementation like so:
Code:
#import "MKNavigationBar"
Once you have done this, in your viewDidLoad method, or the method where you would like to implement the navigationBar subclass you can write the following code:
To set the backgroundImage:
Code:
MKNavigationBar *navigationBar = [[[MKNavigationBar alloc] initWithFrame:CGRectMake(0,0,320,44)] autorelease];
[navigationBar setBackgroundImage:[UIImage imageNamed:@"imagename.png"]];
[self.view addSubview:navigationBar];
To add a titleView
Code:
[navBar setTitle:@"MKNavigationBar" colour:[UIColor whiteColor] andFont:[UIFont fontWithName:@"Futura" size:16]];
To clear the title:
Code:
[navBar clearTitle];
To clear the backgroundImage:
Code:
[navBar clearBackgroundImage];
If you have any suggestions for helper classes/tutorials please do post below or send me a PM.