Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just as an additional thought, I managed to achieve a completely customized navigation bar by overriding <code>drawRect:</code> to have it display a background image. From there, it was easy to set the <code>leftBarButtonItem</code>, <code>rightBarButtonItem</code>, and <code>titleView</code> properties of my navigation controller's <code>navigationItem</code> property to achieve custom buttons and titles. This works with the built-in navigation controller/navigation bar/navigation item logic, so there's no risk of things (like bar buttons) being hidden or obscured.</p> <p>In a <code>UINavigationBar</code> category:</p> <pre><code>- ( void )drawRect:( CGRect )rect { [ [ UIImage imageNamed:@"background-image.png" ] drawInRect:CGRectMake( 0, 0, self.frame.size.width, self.frame.size.height ) ]; } </code></pre> <p>Right before calling <code>pushViewController:animated:</code>, do something like this:</p> <pre><code>UIButton * leftButton = [ UIButton buttonWithType:UIButtonTypeCustom ]; leftButton.frame = CGRectMake( 0.0, 0.0, 65.0, 32.0 ); [ leftButton setImage:[ UIImage imageNamed:@"left.png" ] forState:UIControlStateNormal ]; [ leftButton addTarget:self action:@selector( leftAction ) forControlEvents:UIControlEventTouchUpInside ]; UIButton * rightButton = [ UIButton buttonWithType:UIButtonTypeCustom ]; rightButton.frame = CGRectMake( 0.0, 0.0, 65.0, 32.0 ); [ rightButton setImage:[ UIImage imageNamed:@"right.png" ] forState:UIControlStateNormal ]; [ rightButton addTarget:self action:@selector( rightAction ) forControlEvents:UIControlEventTouchUpInside ]; UIImageView * titleView = [ [ UIImageView alloc ] initWithImage:[ UIImage imageNamed:@"title.png" ] ]; UIBarButtonItem * leftBarButtonItem = [ [ UIBarButtonItem alloc ] initWithCustomView :leftButton ]; UIBarButtonItem * rightBarButtonItem = [ [ UIBarButtonItem alloc ] initWithCustomView:rightButton ]; nextController.navigationItem.leftBarButtonItem = leftButtonItem; nextController.navigationItem.rightBarButtonItem = rightButtonItem; nextController.navigationItem.titleView = titleView; </code></pre> <p>It's a little busy perhaps, but you could abstract away all this code into a method (or series thereof) somewhere else. This approach tends to work well if you want to completely override any of the styling that occurs in your navigation bar.</p> <p>Hope this helps!</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