White pixels around custom navigation bar image - ios

In my iOS 5+ app, I use a custom navigation bar image, with custom navbar buttons.
First of all, here is how I tell my app to use the images :
In AppDelegate.m :
UIImage *navBarImage = [UIImage imageNamed:#"Navbar"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
UIImage *barButton = [[UIImage imageNamed:#"Nav-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
So, the images are used. Great. But, there are a couple of things happening :
• First, on my button, under the bottom corners, au few white pixels appear (they're not on the original image, that's for sure). I also use a custom back button, and same thing happens. This seems to be more visible under iOS 6 than iOS 5.
• When I open a modal VC, the navigation bar is "filled up to the status bar" with white pixels. Only for a modal VC.
Here are screenshots of the situation.
iOS 5 , main VC.
iOS 5, modal VC.
iOS 6, main VC.
iOS 6, modal VC.
So, what can I do ? The white pixels under the buttons are not highly visible (a bit more for the back button), but I really want a nice design for the app, and this doesn't contribute at all..
Concerning the modal VC, I can use a "rectangle" image, which could cover the white pixels, but again, regarding design consistency, I'd prefer to use only one navigation bar..
As always, any explanation / solution / hint is greatly appreciated ! ;)
Thanks.
EDIT :
I just noticed that under iOS 6, the white pixels on top of the navigation bar are rounded, as the navigation bars in iOS 6.. Strange.. :)

Hm! just for testing purpose, can you download the following sample image for a navigation bar background and try this image instead? Just let us now how it looks with this image.
I'm just guessing, but i suppose your image is not pixel perfect for the navigation bar dimensions! Probably a few pixels below the optimum height for the navigation bar.

Related

what size should I use to put a background image on the navigation bar

I'm looking on the internet and I'm told that the sizes should be 320x44 and 640 x 88, but I tried these and I have the following result:
The duplicate image to fill the entire space of the navigation bar, which are the correct sizes and as an achievement also that does not cover the state bar. Thank in objective C
If you are attempting to add color overlay customize navigation controller and add subview with autolayout. It worked for me to place a logo in one of my project.
Your image has the wrong mode.
When you are setting your image, use the following to create the bars image for the appropriate fill / layout mode:
UIImage *barImage = [[UIImage imageNamed:#"imageName"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)
resizingMode:UIImageResizingModeStretch];
Now you can go about setting your navigation bars background image with either UIBarMetricsDefault or UIBarMetricsDefault
[[UINavigationBar appearance] setBackgroundImage:barImage forBarMetrics:(UIBarMetrics)];
OR if you are just setting this within your view controller with a parent navigation controller:
[self.navigationController.navigationBar setBackgroundImage:barImage forBarMetrics:(UIBarMetrics)];
This will set your image as the background image with the correct resizing to ensure it fills the entire navigation bar. Happy coding!

Strange appearance of NavBar background image on iOS7

The following code for setting bkg image of Navigation bar works well on iOS6, but gives strange result on iOS7.
UIImage *navBackgroundImage = [UIImage imageNamed:#"nav-bkg.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
This is result on iOS 6.
As you can see something is wrong for iOS 7.
UPDATE
resized to 64x64px
Guessing because the nav bar is larger on the Y-axis on iOS7 (since it includes the status bar) and your image is just sized for the iOS 6 nav bar. Create an image that is large enough for both versions.
You can see that on ios7, the images is also behind the status bar, and the scrambled part of the image bottom is exactly the height of the status bar.

iOS 7 Navigation Bar

Trying to use a background image that is bigger that than the regular size with some details that hang off the bottom.
So I'm doing this to set the image:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav_bar_home.png"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setClipsToBounds:NO];
[self.navigationController.navigationBar setTranslucent:NO];
And It's still getting clipped.
Some other things I've tried:
Splitting the image up in Photoshop and setting the top 44points (the size that logs out when I log out the navigationBar's frame) to the backgroundImage and the rest to the shadowImage.
From memory this worked fine in iOS 5, 6.
Is there a nice way to do this now? Thanks :)
I'm pretty sure that I remember from one of the WWDC 2013 videos that what you were doing in iOS 5 and 6 (nav bar background view larger than the nav bar "with some details hanging off it") was considered wrong and they are no longer allowing it.
However, if you are supplying your own background image you can add a custom shadow image.

Do I need to supply separate navigation bar png file for iOS landscape mode and how do I get it to show?

I am using Xcode storyboard to demo an app design (non-functional, I'm a designer and need to show for design purposes). So far I have created the necessary png's for navigation bar on top and the tab bar in portrait mode. My navigation bar is 640px × 88px for retina. So I presume I will need to create another png at 1136px x 88px correct? Same with the tabbar?
How can I show this in storyboard so that when I rotate the simulator it will use the larger image intended for landscape?
The best way to customise something universal (such as a navigation bar, that will probably be visible throughout more than one screen) is to use [UINavigationBar appearance]. You can assign it the background you want for portrait mode like this:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"name_of_portrait_png"] forBarMetrics:UIBarMetricsDefault];
And for landscape:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"name_of_landscape_png"] forBarMetrics:UIBarMetricsLandscapePhone];
Also, I'm pretty sure these are customisations that you won't be able to do/see in your storyboard.

UINavigationBar right button too tall

I'm using custom images for UINavigationBars and UIToolbars. The problem i'm having is on 1 of my views that uses a UINavigationBar, the right button appears too tall
On the views that use a UIToolbar (modal views so no Nav bar) they look fine
What could be causing the button to be too large? I've tried adding the button in IB and also using code. Then set the image like this
UIImage *barButton = [[UIImage imageNamed:#"ButtonBlue"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 8, 6, 8)];
[self.connectButton setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Thanks
Create a smaller button. You can do this in Preview - resize it. Make sure you have #2x sizes too. T cannot recall the recommended size for theses images - it's something like 30 points or so (search and you'll find it for sure).

Resources