I have created a custom white image ( 640 x 128 pixel ) and set it as background for the navigation bar using:
[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
UIImage* navBarBackgroundImage = [UIImage imageNamed:#"navbarWhite.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
My goal is to have both navigation and statusbar with a white background.
As far as I test it in the simulator everything looks fine, means both nav and statusbar have a white background.
As soon as I run it on my iPhone 4S the statusbar turns light gray..
Additional info:
UINavigationBar Style UIBarStyleDefault Translucent
UIStatusBarStyleDefault
I am using navigation controllers.
Any idea?
Related
I'm trying to handle the rotation of a UINavigationBar with UINavigationItem (i'm not using the UINavigationController), i have successfully made so that the height and width show according, but that does not seems to be correct, as the UINavigationBar still acts as being in portrait mode (big title and button), also when i set a custom background for both metrics, it seems to only show the portrait background metric, ignoring completely the landscape one.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"modal-top-landscape"] forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"modal-top"] forBarMetrics:UIBarMetricsDefault];
Is there a way to tell the UINavigationBar that is rotated and should show the text and buttons accordingly?
I attach some screenshots:
One workaround for this is to use a UINavigationController, and use a CGRectOffset to remove the margin that leaves the status bar... add the Controller to the parent controller (also the view).
I am using UIAppearance as introduced in iOS 5 to set a custom background image for all the BarButtonItems in my app.
The following code is what I use to set it for the back button, and it works fine in portrait mode. However, when the phone is rotated to landscape and the navigation bar is resized, the button does not get resized at all and is cut off at the bottom.
I thought it would do this automatically since I set the edge insets to not care about vertical resizing. Any ideas?
UIImage *colorViewBBIImage = [[UIImage imageNamed:#"backButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 17, 0, 7)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:colorViewBBIImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
My non-retina image is 30px x 31px.
For landscape mode, just call the second line of your code with last parameter UIBarMetricsLandscapePhone
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:colorViewBBIImage forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
I'm trying to set the tintColor of a UIBarButtonItem in method that gets called when my program starts. I set up all my views using storyboards. I then customize the appearance of the views using the new iOS5 guidelines for using appearance proxies. I've customized the background of the navigation bar by doing the following:
- (void)customizeAppearance
{
UIImage *leatherTexture = [[UIImage imageNamed:#"BrownLeather#2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:leatherTexture
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:leatherTexture
forBarMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearance] setTintColor:[UIColor clearColor]];
}
I was hoping that by setting the UIBarButtonItem tintColor to clear would allow me to easily use the default button styles while having a custom background texture. However, setting the tintColor to clear just turns the button black as opposed to being transparent or clear. Any ideas what I'm doing wrong? Is there a way to create a clear button without having to use custom images for the buttons? See the image below:
You can't do this way (because IMO the default background of UIBarButtonItem is black. and new tint color is over-layered on it).
However you can customize your UIBarButtonItem with using UIButton (with background) as customView in UIBarButtonItem.
Or if you are targeting iOS 5 only you can use brown tint color (which will be flat and will not show background image)
Just found out that in Xcode 4.5 you can just drag a UIButton into the UIBarButton in the Storyboard. The UIButton is then fully customizable.
How to add colour to the navigation bar ? I need to implement this for iOS 4 and above.
I want a colour similar to the one in the screenshot:
In the example you posted, It looks more like a backround image because of the slight lighting effect. (It's brighter in the middle, it you look closely. In IB, I have the nav bar set to Black Transparent with the following Background Image. (320 x 44px)
h file.
IBOutlet UINavigationBar *navBar;
m file "viewDidLoad" function:
navBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"nav"]];
In iOS < 5 you can set tint color of individual navigation bar directly, e.g.:
// self is a UIViewController
[self.navigationController.navigationBar setTintColor:[UIColor purpleColor]];
Once you don't need compatibility with iOS 4.x you can use appearance proxy for UINavigationBar. This would work for all navigation bars in the application:
[[UINavigationBar appearance] setTintColor:[UIColor purpleColor]];
SO I am setting a UINavigationBar tintColor and here's what I get:
[navController.navigationBar setTintColor:[UIColor whiteColor]];
How is this even possible? Here's some more info if it helps:
I've got a UINavigationController that I customize as follows:
First, come up with a 44px-high image as the background for the nav bar. (In this case, if you wanted to use a 44px-high white image, that'd do the trick --- but it'll look much nicer if you use some type of vertical gradient)
Second, use the following code in your AppDelegate's didFinishLaunching method. (The image is called "background_44.png".
// Set the background image for *all* UINavigationBars
UIImage *gradientImage44 = [[UIImage imageNamed:#"background_44.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set the background image for *all* UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:gradientImage44
forBarMetrics:UIBarMetricsDefault];
I dropped that code in my project, worked fine. Even changed bar styles and colors. No problem. This line of code is fine, there is an issue somewhere else or its some crazy glitch.