Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One of the best solutions is creating a category of UINavigationBar and UIToolbar. The next classes gives you a solution for iOS 4.0 and iOS 5.0 compatibility:</p> <p>The only thing is you need to call the next methods in your viewDidLoad for example:</p> <pre><code>// Customizacion de navigation bar y toolbar compatible con iOS4 e iOS5 [UINavigationBar iOS5UINavigationBarBackgroundImage]; [UIToolbar iOS5UIToolbarBackgroundImage]; </code></pre> <p>So, the class Category for iOS 4.0 and iOS 5.0 compatibility for customize BackgroundImage results like follow:</p> <pre><code>@implementation UINavigationBar (BackgroundImage) - (void)drawRect:(CGRect)rect { UIImage* img = [UIImage imageNamed: @"navigation-bg.png"]; [img drawInRect: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; [self setTintColor:UIColorFromRGB(0x5ca666)]; } + (void) iOS5UINavigationBarBackgroundImage { if ([UINavigationBar respondsToSelector: @selector(appearance)]) { [[UINavigationBar appearance] setBackgroundImage: [UIImage imageNamed: @"navigation-bg.png"] forBarMetrics: UIBarMetricsDefault]; [[UINavigationBar appearance] setTintColor:UIColorFromRGB(0x5ca666)]; } } @end @implementation UIToolbar (BackgroundImage) - (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed: @"toolbar-bg.png"]; [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; [self setTintColor:UIColorFromRGB(0x5ca666)]; } + (void) iOS5UIToolbarBackgroundImage { if ([UIToolbar respondsToSelector: @selector(appearance)]) { [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed: @"toolbar-bg.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; [[UIToolbar appearance] setTintColor:UIColorFromRGB(0x5ca666)]; } } @end </code></pre> <p>Greets!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload