Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, December 23, 2015

IOS 7 Navigation Bar text and arrow color

IOS 7 Navigation Bar text and arrow color


I want to set background for Navigation Bar to be black and all colors inside it to be white.

So, I used this code :

[[UINavigationBar appearance] setTitleTextAttributes:       [NSDictionary dictionaryWithObjectsAndKeys:        [UIColor whiteColor],        NSForegroundColorAttributeName,        [UIColor whiteColor],        NSForegroundColorAttributeName,        [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],        NSForegroundColorAttributeName,        [UIFont fontWithName:@"Arial-Bold" size:0.0],        NSFontAttributeName,        nil]];  

But back button text color, arrow and bar button have still default blue color.
How to change those colors like on image below?

enter image description here

Answer by Bhavin for IOS 7 Navigation Bar text and arrow color


Behavior from some of the properties of UINavigationBar has changed from iOS 7. You can see in the image shown below :

enter image description here


Two beautiful links I'd like to share with you. For more details you can go through these links :

  1. iOS 7 UI Transition Guide.
  2. How to Update Your App for iOS 7.

Apple Documentation for barTintColor says :

This color is made translucent by default unless you set the translucent property to NO.

Sample Code :

self.navigationController.navigationBar.barTintColor = [UIColor blackColor];  self.navigationController.navigationBar.tintColor = [UIColor whiteColor];  [self.navigationController.navigationBar    setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];  self.navigationController.navigationBar.translucent = NO;  

Answer by John Riselvato for IOS 7 Navigation Bar text and arrow color


enter image description here

This one took me about half a day to figure out but this is what worked for me. Inside the rootViewController that initializes the navigationController, I put this code inside my viewDidAppear method:

//set bar color  [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];  //optional, i don't want my bar to be translucent  [self.navigationController.navigationBar setTranslucent:NO];  //set title and title color  [self.navigationItem setTitle:@"Title"];  [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];  //set back button color  [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];  //set back button arrow color  [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];  

My full post on this here

Answer by benhorgen for IOS 7 Navigation Bar text and arrow color


Vin's answer worked great for me. Here is the same solution for C# developers using Xamarin.iOS/MonoTouch:

var navigationBar = NavigationController.NavigationBar; //or another reference  navigationBar.BarTintColor = UIColor.Blue;  navigationBar.TintColor = UIColor.White;  navigationBar.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White });  navigationBar.Translucent = false;  

Answer by aZtraL-EnForceR for IOS 7 Navigation Bar text and arrow color


To change color of UINavigationBar title the correct way use this code:

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];  

UITextAttributeTextColor is deprecated in lastest ios 7 version. Use NSForegroundColorAttributeName instead.

Answer by CPU 100 for IOS 7 Navigation Bar text and arrow color


I think previous answers are correct , this is another way of doing the same thing. I am sharing it here with others just in case if it becomes useful for someone. This is how you can change the text/title color for the navbar in ios7:

UIColor *red = [UIColor colorWithRed:254.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0];  NSMutableDictionary *navBarTextAttributes = [NSMutableDictionary dictionaryWithCapacity:1];  [navBarTextAttributes setObject:red forKey:NSForegroundColorAttributeName ];  self.navigationController.navigationBar.titleTextAttributes = navBarTextAttributes;  

Answer by Abo3atef for IOS 7 Navigation Bar text and arrow color


[[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];  

Answer by LondonGuy for IOS 7 Navigation Bar text and arrow color


Swift / iOS8

let textAttributes = NSMutableDictionary(capacity:1)  textAttributes.setObject(UIColor.whiteColor(), forKey: NSForegroundColorAttributeName)  navigationController?.navigationBar.titleTextAttributes = textAttributes  

Answer by strangeluck for IOS 7 Navigation Bar text and arrow color


It seems that Accessibility controls in the iOS Settings override pretty much everything you try to do color-wise to the navigation bar buttons. Make sure you have all the settings to the default positions (set increase contrast, bold text, button shapes, etc to off) otherwise you won't see anything change. Once I did it, all the color change code started working as expected. You might not need to turn them all off, but I didn't pursue it further.

Answer by OhadM for IOS 7 Navigation Bar text and arrow color


If you're looking to change the title text size and the text color you have to change the NSDictionary titleTextAttributes, for 2 of its objects:

    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:13.0],NSFontAttributeName,                                                                    [UIColor whiteColor], NSForegroundColorAttributeName,                                                                     nil];  

Answer by lifeisfoo for IOS 7 Navigation Bar text and arrow color


Swift, latest ios

To globally assign the color, in AppDelegate didFinishLaunchingWithOptions:

let textAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]  UINavigationBar.appearance().titleTextAttributes = textAttributes  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.