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.
Related
When I try to modally present a view controller the bar buttons on either side of the title of navigation bar are not showing up. This happens only when the "Buttons Shapes" accessibility feature is turned on under iPhone settings menu. It just shows up a plain blank white space. But when I try to tap the button I could see the button's presence and the button shape drawn around it.
Could some help and point me in right direction ?
Thanks
Check how you set tintColor, barTintColor, and barStyle of UINavigationBar's appearance. For a dark background and light foreground it works like this.
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
It's all advisable to look at UIBarButtonItem's appearance, e.g. titleTextAttributes.
See also this answer.
When choosing a sharing option from the activity view such as message or email composing, the navigation bar (or is it a toolbar) and title colours look terrible. The title and status bar items are almost unreadable.
I have tried to change navigation bar and toolbar tint, barTint, background and title colours with no luck. Also tried to toggle between default and light styles.
Changing navigation bar tint colours on the main view itself also renders no difference.
Any idea on how to solve this?
Are you using a custom background image for the navigationbar? If so, you need to set the background image to nil before presenting the compose sheet. Something like:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Otherwise,
[[UINavigationBar appearance] setBarTintColor:[UIColor WhiteColor]];
should work.
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.
The release of iOS 7.1 brings the availability of Button Shapes under the Accessibility settings. I've noticed that their appearance can be inconsistent within my app. Mostly, I'm getting a black background after having implemented a UIBarButtonItem using Interface Builder. Touching the button but not fully tapping it results in the image turning gray. How can the appearance of the button shapes be influenced so that they will not look so out of place as having a solid black background and more like the gray background as shown in the attached image? In this case I do not want to use a custom control.
This feature seems to be a little buggy in iOS 7.1. The setting that seems to influence the appearance the most is actually the barTintColor on your UINavigationBar.
Some examples:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBarTintColor:[UIColor lightGrayColor]];
return YES;
}
When I first launch, the back button looks fine:
Then when I go to landscape, it looks way too dark:
And it then stays too dark when I go back to portrait:
The same thing happens when I use [UIColor orangeColor] as the barTintColor.
First it`s fine:
In landscape it gets messed up:
And it then stays that way:
So it clearly looks like a bug in iOS 7.1. One thing that can be done is to set a background image for the back button. This background will then display whether "Button Shapes" is activated or not. Example:
UIImage *backButtonImage = [[UIImage imageNamed:#"back_button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 17.0f, 0.0f, 1.0f) resizingMode:UIImageResizingModeStretch];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsLandscapePhone];
So the big question is: Can we set the button background image when "Button Shapes" is turned on in a way that is independent of the barTintColor?
-[UINavigationBar setTranslucent:NO] seems to correct this. I don't know why, but it does.
Alas, we couldn't set -[UINavigationBar setTranslucent:] using UIAppearance so had to sprinkle it around the app.
I just ran into an issue similar to one described in the comments of one of the answers here while using a barTint color fairly close to black. My button shape backgrounds were nearly the same color as the barTint on a few of my UINavigationBar instances, rendering them almost impossible to see (especially when the buttons were not enabled). I tracked down the difference in these instances to be the value of the UINavigationBar instances barStyle property.
With barStyle set to UIBarStyleDefault, the button shapes would show up with a background color. With barStyle set to UIBarStyleBlack, the buttons shapes would show up with a light color. You can also notice this in the storyboard, as the title shown in the navigation bar will be black with the default style and white with the black style.
You can change each navigation bar's style in your storyboard/NIB, or alternatively you can add the following line of code where you setup your appearance proxies (typically in application:didFinishLaunchingWithOptions:):
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
My iOS 7 app uses a custom background image for the navigation + status bar. It works fine but when the content of a view is scrolled up behind the navigation/status-bar it will not get blurred the way like when not using a custom image. Instead the content appears still quite sharp. Is there a way to add the blur effect?
I simply us in my delegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbarimage#2x.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbarimage_landscape#2x.png"] forBarMetrics:UIBarMetricsLandscapePhone];