Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is setting my UINavigationBar's background image affecting the size of the navigation bar?

I'm doing something like this:

UIImage *barBackgroundImage = [UIImage imageNamed:@"myImage.png"];
[[UINavigationBar appearance] setBackgroundImage:
                                    backgroundImage
                                   forBarMetrics:UIBarMetricsDefault];

And the resulting UINavigationBar is much larger than the standard navigation bar. I'm aware that my image size might be the problem. Is there any way to take care of this programmatically?

like image 501
sparkFinder Avatar asked Apr 16 '12 21:04

sparkFinder


People also ask

How do I change my navigation bar background?

In order to change the hub navigation bar color, we can go to site settings of hub site>Change the look>under the header section>Background> select a theme color to change the background color of your site header.

How do I fit an image into a navigation bar?

We just need to add a div tag with the class as a container and put the navbar-brand(image or logo) inside this div. After that, we just need to add the class mx-auto to the navbar-brand class.


2 Answers

This is how I set the UINavigationController's navigationBar background image.

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTintColor:LIGHTBROWN];

navbar.png is 320x44 and respectively 640x88 for [email protected].

like image 186
WrightsCS Avatar answered Oct 14 '22 04:10

WrightsCS


Follow this link to make your code compatible with iOS4, 5 and 6: http://robert-varga.com/?p=735

You just have to make in Photoshop or other software a rectangular with the size of 320x44 or 640x88 (for retina display) and import it to your project

like image 2
Robert Varga Avatar answered Oct 14 '22 04:10

Robert Varga