Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging the UINavigationBar background image
    primarykey
    data
    text
    <p>I've been trying to change the background image of the UINavigationBar of my application. I tried several ways. First I added to my AppDelegate class the following code:</p> <pre><code>@implementation UINavigationBar (CustomImage) - (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed: @"navigationbar.png"]; [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; } @end </code></pre> <p>But it wasn't working. My next try was to write a CustomizedNavigationBar Class which is overriding the <em>drawRect</em> method. It looked like that:</p> <p><strong>CustomizedNavigationBar.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomizedNavigationBar : UINavigationBar @end </code></pre> <p><strong>CustomizedNavigationBar.m</strong></p> <pre><code>#import "CustomizedNavigationBar.h" @implementation CustomizedNavigationBar - (void) drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed: @"navigationbar.png"]; [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; NSLog(@"I got called!!!!!"); } @end </code></pre> <p>In my .xib file where the NavigationBar is defined I changed the class to the new CustomizedNavigationBar. But still it is not working..</p> <p>As another test I downloaded an example project where the background image should be changed. But even with that sample code it was not working. </p> <p>What am I doing wrong? I am using IOS 5. Any suggestions or other ways I could define a background image?</p> <p>Thanks for your answers!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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