I have a global background image (basically some orange color) which is set for all navigation bars inside the AppDelegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"order-navbar"] forBarMetrics:UIBarMetricsDefault];
This works for all views except one: I have an MFMailComposeViewController whose navigation bar background stays white-gray no matter what I do:
let mailController = MFMailComposeViewController()
mailController.navigationBar.tintColor = UIColor.whiteColor() // this works
emailController.navigationBar.setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does not
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does neither
However, sometimes the mail controller appears at first with the orange bar and then suddenly changes its color to white-gray again.
On iOS 8 everything works. Is this an iOS 9 bug?
Related
I have an iOS 7 app that has a NavigationController inside TabbarController.
I then customize the bars background color
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
It runs fine. But if there's a ViewController that wants not to be covered by the bars, like this
self.edgesForExtendedLayout = UIRectEdgeTop;
Which means this ViewController does not want to be covered by the Tabbar. But it makes the Tabbar darker than normal
I think this is because I use custom color for the bars. How to fix ?
It probably means that the there's nothing to show below the translucent tab bar. Set the tab bar translucent property to NO
#rounak is right, maybe setting the tab or nav bar's translucency to NO tells iOS not to try to put another tab or nav bar under the current one, which makes it darker.
In the viewDidLoad, add this:
self.navigationController.navigationBar.translucent = NO; // if you have a nav
self.tabBarController.tabBar.translucent = NO; // if you have a tab
How do you change the title color and/or bar tint color in a SKStoreProductViewController?
I'm using the appearance API to set navigation bars to a dark color and the text to white. It changes the title color but not the bar tint color in my SKStoreProductViewController.
I don't think you can. At least not on iOS 7. On iOS 6 you can use the UIAppearance protocol and the SKSPVC will pick up the appearance you set on the UINavigationBar.
As noted on this thread, the SKSPVC is a remote view controller so it's inaccesible programmatically, meaning that you can't set it's appearance directly (or indirectly?).
Do the following to avoid the SKStoreProductViewController to take over a tintColor of value WHITE:
#define kCOLOR_NON_WHITE_COLOR [UIColor darkGrayColor]
// CHANGE ALL TINTING BEFORE WE CREATE An INSTANCE OF THIS BROKEN PIECE
[UIWindow appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIView appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UINavigationBar appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIBarButtonItem appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
// NOW CREATE THE THING
SKStoreProductViewController *controller = [[[SKStoreProductViewController alloc] init] autorelease];
This draws all the UIBarButtonItems and the UISegmentedControls in this controller in the defined color AFAIK and thus makes the controller more like your apps design.
IMPORTANT: Just do not forget(!!!) to change all the tinting back after you dismissed this controller, otherwise fresh created views in your app might take over the enforced tinting.
UPDATE: As you might already have found out the following to manipulate the appearance does not work:
[UINavigationBar appearanceWhenContainedIn:[SKStoreProductViewController class], nil]
This fix is for iOS 7 & 8 on iOS 6 you have different issues. =)
Am trying to set the tint for all navigation bars from my appdelegate in iOS 7. This worked always before, but for some reason now, nothing is changing. In the didFinishLaunching part of my appDelegate I have:
[[UINavigationBar appearance] setTintColor:toolbarcolor];
However, the bar stays the default translucent option.
You can set the bar tint color using the barTintColor property:
[[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
If you also don't want the navigation bar to be translucent, you can set the translucent property to NO.
Unfortunately, the translucent property is not available on the UINavigationBar appearance proxy, so you will have to set this property individually (in your storyboard, .xib, or in something like viewDidLoad in your controller).
Swift version:
UINavigationBar.appearance().barTintColor = colorBar
If you want to set bar tint color for whole application, write in "didFinishLaunchingWithOptions" method of AppDelegate.m
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
Following is output :
In Swift 3.0
let navigationBarAppearnce = UINavigationBar.appearance()
A navigation bar’s tintColor affects the color of the back indicator image, button titles, and button images:
navigationBarAppearnce.tintColor = UIColor.white
The barTintColor property affects the color of the bar itself:
navigationBarAppearnce.barTintColor = UIColor(red: 0.180, green: 0.459, blue: 0.733, alpha: 1.00)
I just updated my phone to IOS 6 but I have some issue regarding adding UIImageView on the UINavigationController navigationbar. This is my code
UIImage *logoImage = [UIImage imageNamed:#"navigationbar.png"];
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:logoImage];
UINavigationBar *navBar = self.navigationController.navigationBar;
[navBar addSubview:logoImageView];
[logoImageView release];
This will add logo on navigationbar, it works great on the lower version of IOS 6. But on IOS 6 the logo shown but the back button was behind the logo so back button is not shown.
I don't want to override the UINavigationBar drawrect since I also have UINavigatioBar somewhere on the code for popup.
Any suggestions?
I think you don't need a UIImageView in IOS 6.
You can just put a background image in the UINavigationBar (for example in AppDelegate) like this:
[[UINavigationBar appearance] setBackgroundImage :[UIImage imageNamed:#"navigationbar"]];
Found a good site which explains some new user interface customisation in IOS 6:
click here
The app I'm working on has a custom nab bar but supports iOS 4.2-iOS 5, so I need to set the UINavigationBar background and tint in this old school way in my app delegate.
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
self.tintColor = [UIColor colorWithRed:42.0/255.0
green:164.0/255.0
blue:182.0/255.0
alpha:1.0];
UIImage *img = [UIImage imageNamed:#"navbar_bg.png"];
[img drawInRect:CGRectMake(0.0, 0.0,
self.frame.size.width,
self.frame.size.height)];
}
#end
This works for the most part, but I noticed when the app is first starting, the UIBarButtonItems flash the default navigation bar color for a second before they correct themselves and change color to match the navigation bar. Interestingly, the navigation bar itself uses the background image correctly from the get-go.
To be clear, I'm using setBackgroundImage for UINavigationBar on iOS 5 devices which works as expected so the flash is only in iOS 4.
Anyone have any insight on why this would happen and/or how to fix it?
The bar button items are the wrong color? You can manually set their tint color in viewDidLoad: to the tint color
navigationBar.rightBarButtonItem.tintColor = [UIColor ...]
if you're using a nib file. Otherwise you can do the same thing in loadView: . Either way this code will get executed as part of the initial draw loop so you'll have the proper color without any flashing.
Also for future reference, it's technically incorrect to override a method inside a category. (The latest version of Xcode, 4.3, will give you a warning about this). You should either properly subclass UINavigationBar or do "method swizzling". But that's pretty tough so don't worry about it right now :)
If you call the class with the code referenced in viewDidLoad try moving it to awakeFromNib