UIImageView *navBarImageView = [[UIImageView alloc] initWithImage:navBarImage];
[navBarImageView setFrame:CGRectMake(0, 0, 320, 44)];
self.navigationItem.titleView = navBarImageView;
[navBarImageView release];
I am trying to add an image to my navigationBar, but when I used the code as listed above, it places the image into the navigationBar but leaves a grey gap to the left and right of the image. The image was created at 320×44, I’m not sure why it is resizing it despite the fact that I am setting the frame.
That’s… probably not how you want to do that—it’s not what the
titleViewis for. The usual way to do a custom navigation-bar background is to create a category onUINavigationBar, like so:Throw that in a .m file in your project and you should see all of your navigation bars use “my-navigation-background.png” as their background.