Strange appearance of NavBar background image on iOS7 - ios

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.

Related

Attached iOS 11-style UISearchBar background image

I'd like to migrate my tableHeaderView based search bar to the new seamless search bar approach in iOS 11 by configuring navigationItem.searchController.
Since my navigation bar uses a custom background image, I'm wondering how to apply the same background image to the search bar as well. I tried
[navigationBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarPromptBackground"] forBarMetrics:UIBarMetricsDefaultPrompt];
[searchBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarBackground"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
to no avail. The search bar keeps the standard navigation bar background (with a barTintColor applied) but doesn't show the custom background image.
In my case I have a UISearchBar in a view, not placed in a UINavigationItem. A transparent background image I was setting wasn't showing up in iOS 11. However if I add a height constraint that forces the searchBar to be smaller the background image gets used for some reason. This is really odd behavior that must be a bug but it is working for me now.
If I do the following the background image gets used:
[[searchBar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];
I do a very similar thing in my application and discovered on IOS11 it's now broken. This is the code I had which sets my image across the Search and Scope bars, works fine up to IOS10:
[searchBarSearch setBackgroundImage:image];
[searchBarSearch setScopeBarBackgroundImage:image];
I fixed it by adding this to the .plist
View controller-based status bar appearance = NO
Now my bar is coloured and changes as I select different options as it did before IOS11.
Hope this helps you!
Plasma

How to set a UINavigation size to fit the background image size?

I've set my UINavigationBar background image to some image, like this:
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:#"Menubar.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
but I cant really see the whole image since its bigger than the default size on a UINavigationBar.
So two things please:
How to set a UINavigation size to fit the background image size?
I dont want to see the battery and time bar in the background, so my image will cover it.
It's not possible to set UINavigation size (take a look at this question), you have to fit the background image instead
It's impossible to cover the status bar, but you can easily hide it. See the example here
you can easily remove status bar using info.plist file
just addRow and write "Status bar is initially hidden" and set value "YES"
end check to navigationBar
iOS. How to change UINavigationBar height and change frames of the others subviews at once?

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.

White pixels around custom navigation bar image

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.

iOS5 UINavigationBar background image issues when prompt is shown

I am using the new appearance proxy in iOS 5 to style my UINavigationBar with a background image.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"ZSNavigationBG.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"ZSNavigationLandscapeBG.png"] forBarMetrics:UIBarMetricsLandscapePhone];
This works fine, but I need to set the prompt property of the nav bar. When I do that, the height of the nav bar increases, and my background image no longer fills that nav bar vertically, so it looks very bad.
How can I account for the height change with a prompt when using a custom background image?
The image should be a stretchable image so it can extend in either direction without breaking anything.

Resources