5

I am trying to set the UINavigationBar background image:

I added in AppDelegate: (please note that it's one image)

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"general-top_bar_with_status.png"] forBarMetrics:UIBarMetricsDefault];

Since I don't need translucent, in the ViewController in ViewDidLoad I added:

self.navigationController.navigationBar.translucent = NO;

This is the image: enter image description here

Unfortunately this is what I get: enter image description here

As you can see, the image is upsite down.

What is wrong?

In storyboard, I set a place for TopBar - Opaque navigation bar

Dejell
  • 13,947
  • 40
  • 146
  • 229
  • 3
    To me, it looks more like it's shifted downwards (and the color on the top has filled in the remaining area). Try actually making it upside down - the lower portion appears darker (and not lighter as it appears in your image). – AbdullahC Oct 06 '13 at 14:48
  • The second image is not exactly the same. – ipinak Oct 06 '13 at 14:48
  • It's one image. Not sure what happened there – Dejell Oct 06 '13 at 14:52
  • I set in storyboard the topbar to Opaque Navigation Controller - could this cause the problem? – Dejell Oct 06 '13 at 14:56
  • can anybody give answer? http://stackoverflow.com/questions/16190127/custom-uinavigationbar-background-image-appears-darker-than-the-original-image – Mashhadi Oct 24 '14 at 07:07

2 Answers2

13

For iOS 7 you have to use 320x64 size navigation bar image

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Divyam shukla
  • 2,038
  • 14
  • 18
  • In my case there were 2 problems, 1. I was using only 2x size, 2. I was using image name as "detailNavBariPad@2x" in my code including with 2x. Image name in coding should not have 2x in their name. – Mashhadi Oct 23 '14 at 13:55
  • what is the dimension of the image ? – Divyam shukla Oct 30 '14 at 10:53
2

make picture 2X Size. with name mynavbar@2x.png

Nav bar is Taking size of its self + status bar size. You may create only navbar size

640X88

or 640X128 for navbar + status bar

Then

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"mynavbar.png"] forBarMetrics:UIBarMetricsDefault];
Anton
  • 3,102
  • 2
  • 28
  • 47