Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Setting custom background for UINavigationBar to support iOS5 and iOS4 too!</strong></p> <p><strike><a href="http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/" rel="nofollow noreferrer">http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/</a></strike></p> <p><a href="http://rogchap.com/2011/06/21/custom-navigation-bar-background-and-custom-buttons/" rel="nofollow noreferrer">http://rogchap.com/2011/06/21/custom-navigation-bar-background-and-custom-buttons/</a></p> <hr> <p>As you know, until iOS 5 came out, we used <code>drawRect</code> override in <code>AppDelegate</code> to customize <code>UINavigationBar</code>. But know, iOS 5 give us some new method for styling (and old doesn’t work).</p> <p>How to build app that will work on iOS 4 and iOS 5 with stylized <code>UINavigationBar</code>?</p> <p>You must to do both!</p> <p>In <code>AppDelegate</code> use this code:</p> <pre><code>@implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { UIImage *img = [UIImage imageNamed:@"navbar.png"]; [img drawInRect:rect]; } @end </code></pre> <p>and in <code>viewDidLoad</code> method for iOS5 (in your view implementation):</p> <pre><code>if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault]; } </code></pre> <p>If you see, here we are asking if navbar will respondToSelector to avoid crash on iOS4! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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