I have some items that change the UINavigationBar color when the detail pages are accessed. My issue is getting back to the default UINavigationBar color. What color is it? It is not blue or gray for sure.
Also when going "back", where is the best place to put this color change? Unload does not seem to work for this. On the table view controller, Placing the color change at the end of the "didSelectRowAtIndexPath" changes it prematurely.
What is the default UINavigationBar color?
Where should I place the change when the user is leaving the detail view?
I think you can just set the navigation bar color to nil and it will revert to its default.
Color : [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
Image : [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navigationBar_320X44.png"] forBarMetrics:UIBarMetricsDefault];
Related
This is what I want. It loads on some of my view controllers.
Hi all,
I am going nuts trying to make the tint color of all of my viewControllers the same. Some appear to be much darker than others. All I want is the light color to be throughout...
Sometimes I get this ugly dark gray instead... I am not sure what I am doing incorrectly. I have checked the .m file and am not setting the tint color or anything... not sure why it wouldnt be consistent on every viewController...
Any help would be great. Thanks!
in iOS7 navigation bar is by default translucent=YES so just change to NO like bellow:-
self.navigationController.navigationBar.translucent=NO;
and set Navigaitonbar color or other property customize like Bellow put this code into Appdelegate class didFinishLaunchingWithOptions and use appearance for applying Globally:-
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
[[UINavigationBar appearance]setTintColor:NavigationColor];
} else {
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; // it set color of bar button item text
[[UINavigationBar appearance]setBarTintColor:[UIColor GreenColor]]; // it set color of navigation
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault]; // it set Style of UINavigationBar
[[UINavigationBar appearance]setTitleTextAttributes:#{UITextAttributeTextColor : [UIColor whiteColor]}]; //It set title color of Navigation Bar
// Load resources for iOS 7 or later
}
For tabBar also same this is by default translucent=YES change to NO
[self.tabBarController.tabBar setTranslucent:NO];
A common mistake is setting the view.backgroundColor of the View Controller to clearColor (both programmatically or via Storyboard). This makes the view actually black instead (since there's nothing beneath the clear view), so everything that is above that view, that has translucent property set to YES, will show dark grey color (black color + default iOS blur).
To fix this, either set the translucent property to NO (as Nitin Gohel said), or set the view.backgroundColor to white, which's its actual default color.
Hope this still helps someone!
Since iOS 7.1 there's a bug, which causes UITabBar to not listen to Global Tint.
See this post: https://stackoverflow.com/a/22323786/1255674
You need to set the tint programmatically. Thanks, Ive ...
This is driving me crazy, I can not figure out what that black line is behind my search bar.
My view hierarchy is a UINavigationController -> UITableViewController with a SearchDisplayController, and I customize the appearance of the search bar with the following code:
[[UISearchBar appearance] setImage:[ApplicationStyle searchBarIconImage] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
[[UISearchBar appearance] setBackgroundImage:[ApplicationStyle searchBarImage]];
[[UISearchBar appearance] setSearchFieldBackgroundImage:[ApplicationStyle searchBarFieldImage] forState:UIControlStateNormal];
The image I am using for the background is 640px x 88px and it is not transparent by any means. Any ideas what this could be?
Set the search bar's clipsToBounds property to YES.
Relevant SO questions:
Is it possible to change the border color of a UISearchDisplayController's search bar?
Get rid of line above UITableView
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'm using a custom Navigation Bar appearance in my app with this code in the App Delegate's application:didFinishLaunchingWithOptions: method:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navBar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]];
However, this appearance breaks when I present an ABPeoplePickerNavigationController (to allow selection of a contact to populate the To: field for a new email), because the system uses an extra tall UINavigationBar when this view is showing due to the prompt property on UINavigationItem being set by the system ("Choose a contact to mail").
The fix is to add this code:
[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarStyle:UIBarStyleBlack];
Which looks like this:
However, this little hack doesn't work when you tap the Groups button from the initial view. It still looks broken due to the extra tall Navigation Bar:
Any ideas what the controller name is for that view (so I can apply the same exclusion as above), or another way to fix this?
I'm just hitting this now.. any luck resolving? I'm thinking to try interating through the ABPeoplepickerNavigationControllers view controllers and applying appearanceWhenContainedIn method...
I've been fighting with this as well, but think I've pieced together a solution.
The group selection view is some other (unknown to me, likely private) class, so we can't specify an exception style through an appearance-proxy-when-contained-in approach, as you've done for the ABPeoplePickerNavigationController. Instead, we should try and resolve the original issue, which is the custom background image not rendering properly when the prompt is shown and the navigation bar is tall.
The solution here (iOS5 UINavigationBar background image issues when prompt is shown) suggests using a resizable background image for the navigation bar.
That almost worked for me, but the background image I was using included the shadow for underneath the navigation bar and that wasn't resizing correctly when the prompt was shown. Instead, I had to use a resizable background image without a shadow and then specify the shadow image separately.
UINavigationBar* navigationBar = [UINavigationBar appearance];
[navigationBar setBackgroundImage:[[UIImage imageNamed:#"TopBarBackgroundNoShadow"] resizableImageWithCapInsets:UIEdgeInsetsMake(3, 0, 3, 0)]
forBarMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImage imageNamed:#"TopBarShadowResize"]];
Using this approach removed the need for any exception styling and looked good in both the ABPeoplePickerNavigationController and the group selection view, as well as at standard height.
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.