I am trying to update my app for iOS7, however I am unable to set the colour of the UINavigationBar at the top of the screen. I have tried the classic approach...
[mailer.navigationBar setTintColor:[UIColor darkGreyColour]];
...however it didn't work. I have also tried calling setBarTintColor instead, however that didn't seem to work either.
Does anyone know if its possible to set the colour and if so how?
I had your same problem when updating my application for iOS 7.
I solved using this line of code (if you use images):
[[UINavigationBar appearance] setBackgroundImage:#"myImage" forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
or this one if you are not using images:
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
I placed then in AppDelegate, just before returning application:didFinishLaunchingWithOptions:
Hope this helps!
Try changing the tint in storyboard. Its in 'view' sub section when you select navigation bar in IB.
Related
When I try to change the background image for a second time for a tab view, nothing happens.
I'm using:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:newBarImageBackGround];
It seems that you need to use something like the following for changing the tab bar's background. Unfortunately, this doesn't fly with appearance.
[[self.tabController tabBar] setBackgroundImage:[UIImage imageNamed:newBarImageBackGround]];
Your code should work for the first time though. Reference: Link
Note: [self.tabController tabBar] should be replaced with whatever reference to a tab bar you're using.
EDIT
You could also try this, but I haven't tested it so I don't know if it'll work.
[[UITabBar appearance] setBackgroundImage:nil];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:newBarImageBackGround]];
Recently I've updated my Xcode IDE to the latest to have iOS 7.1 SDK. For some reason, after recompiling my app with the new Xcode I get this wired UINavigationBar background colour.
I'm using storyboard to push the secondary view controller from home screen. The secondary view controller is a static table of settings, also built using storyboard, and contains the following code in its viewDidLoad method:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
I haven't done any other changes to this screen or any other screens in the app.
This is how it used to look like before:
This is how it is look like now:
Does anyone have any idea what could have caused this?
Cheers,
EDIT: #Leo Natan -
When I'm trying to set the color myself, for example, by replacing this line:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
with this line:
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
I get this: the red color applied only on the header without the status bar, what can I do?
Latest Xcode comes with iOS7.1 SDK, in which Apple once again changed how the color is calculated. You will have to play again with your color to achieve a similar look in iOS7.1.
Maybe you should take another approach. Use the Appearance Proxy in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. Thats how I do it:
//Navigationbar
[[UINavigationBar appearance] setBarTintColor:lightOrangeColor];
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes: #{NSForegroundColorAttributeName : [UIColor whiteColor]}];
I'm resetting the NavigationBar's background image by calling setBackgroundImage when showing an MFMailComposeViewController. But when I try to reset the image to its original by calling setBackgroundImage a second time in mailComposeController:didFinishWithResult:, it doesn't visibly change the background image.
The weird thing is that the log shows me that the NavigationBar's background image has changed, and after I pop a few view controllers (I'm not sure which are modal transitions and which aren't, because it's somebody else's code), the background image finally does change. But why doesn't it change immediately?
Here's my relevant code inside mailComposeController:didFinishWithResult::
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"img"]
forBarMetrics:UIBarMetricsDefault];
NSLog(#"Navbar img = %#", [[UINavigationBar appearance]
backgroundImageForBarMetrics:UIBarMetricsDefault]);
Another suggestion is to make sure that you are setting the background image after you've dismissed the mailComposeController and after your own view controller has become active again.
Are you sure that your -mailComposeController:didFinishWithResult: is being called on the main thread, where you need to be doing all of your ui work?
Try executing your -setBackgroundImage:forBarMetrics: call on the main thread and see if this helps.
For example:
dispatch_async(dispatch_get_main_queue(), ^{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"img"]
forBarMetrics:UIBarMetricsDefault];
});
I'm using this piece of code to set the default font (Custom) for all my UIBarButtonItems:
NSDictionary *attributesBarButtonItem = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:#"ProximaNova-Light" size:18.0], NSFontAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributesBarButtonItem forState:UIControlStateNormal];
NSLog(#"%#", [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]);
However, it seems to be ignored as the font does not change, and NSLog returns (null). It's a bit confusing because its pretty much the same code I'm using to set the default font for all my navigation bars and it works fine for them.
The piece of code is placed in AppDelegate´s didFinishLaunchingWithOptions but I've also test it in other viewControllers (viewDidLoad) with exact same result.
Other strange behaviour I've noticed:
I've got a tab bar controller, and when I load any viewController with bar button items it doesn't work, but if I push another viewController it works (The font is changed to the selected one), and it keeps working even if that viewController is popped out, although it will stop working if another tab is pushed.
Any help to try to set a default font for the UIBarButtonItems would be appreciated. Thanks!
Is this your custom font ?
There could be few problems:
is the font in TTF format ?
if you click on the font in xcode is Target membership in right panel checked ?
did you add the font to project plist file ?
Also you should use UITextAttributeFont in the dictionary:
[UIBarButtonItem appearance] setTitleTextAttributes:#{UITextAttributeFont:[UIFont fontWithName:#"ProximaNova-Light" size:18.0]} [forState:forState:UIControlStateNormal];
I had a similar issue arise because I was creating the leftBarButtonItem before I set the appearance attributes. Swapping the order such that appearance was set first fixed the problem.
My iPad app I has a number of UIButtons that when pressed turn blue by default. I could go through each one and set the tintcolor using:
[buttonName setTintColor:[UIColor colorWithRed:151/255.0f green:202/255.0f blue:86/255.0f alpha:1.0]];
But is there anyway of changing this colour by default and for all buttons?
Is there anyway of changing this colour?
If you are using storyboards and Xcode 5.0 or later, the easiest way to do this is to open up your storyboard in Xcode and set the Global Tint color setting in the File Inspector in the Utility area. See illustration below.
Use the UIAppearance Protocol:
[[UIButton appearance] setTintColor:[UIColor colorWithRed:151/255.0f green:202/255.0f blue:86/255.0f alpha:1.0]];
You could subclass uibutton and set the color to whatever you want there. Then any button with that class will have the same color