Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials

Reply
 
LinkBack Thread Tools Display Modes
Old 05-25-2011, 04:35 PM   #1 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default Setting the background image of a UINavigationBar

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.
iSDK is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 477
14 members and 463 guests
alexeir, David-T, Dj_kades, foslock, iAppDeveloper, jeroenkeij, LunarMoon, Mijator, Pauluz85, pipposanta, QuantumDoja, robsmy, sacha1996, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0