Custom Background Image UINavigationBar

I used these proposed solutions to give UINavigationBar my own image. (To make it more explicit: I added a category to the UINavigationBar in the AppDelegate.m file). So far this has worked fine and I have not had any problems. Now, however, I ran my application on the recent beta version of iOS5. UINavigationBar is empty again.

Since all the other applications that I installed that use the user image still behave the same, there should be something “wrong” in my code. I believe iOS5 is no longer supported.

Anyone have an idea what could be the problem with my making the above decisions?

The only way I worked with is to create a real subclass of UINavigationBar, and then in all views specify IB to use this custom class. Not so elegant though ...

+4
source share
4 answers

To support both versions, you need to ask if there is a setBackgroundImage: forBarMetrics: method method.

Take a look at my blog post about this: http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/

+4
source

Another possible “hacked” solution is to create a custom view and paste it into the UINavigationBar as a subspecies - it may work anyway:

UIView *backgroundView = ... [navigationBar insertSubview:backgroundView atIndex:0]; 

Or check out the updated link of the UINavigationBar class in iOS5 docs for the built-in method for setting custom background

+1
source

Use this code

  UIImage *backgroundImage = [UIImage imageNamed:@"strip.png"]; [upnavbar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; 

this work wil.

+1
source

It worked for me on my instrument

 //toolBar background image set based on iOS version [[UIDevice currentDevice] systemVersion]; if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) { //iOS 5 UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"]; if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) { [toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0]; } } else { //iOS 4 [toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0]; } 
0
source

All Articles