Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 Navigation bar text colour

Tags:

I'm having problems changing the text and status bar text colour to white.

I want all the black text to be white,any ideas?

I have seen a lot of solutions but none seem to work on iOS 7

like image 251
Jason Wragg Avatar asked Sep 19 '13 20:09

Jason Wragg


People also ask

How do I change the color of my navigation bar title?

Changing the text color The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color.

Can you change Iphone navigation bar?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


2 Answers

My solution was to add the following to AppDelegate:

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

Swift 3:

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

Swift 5:

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

In iOS 13 you can set the appearance on a navigation bar itself using UINavigationBarAppearance:

let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

navigationBar.standardAppearance = appearance
like image 91
Leon Avatar answered Sep 30 '22 12:09

Leon


To turn your title text color white put this in your viewDidLoad

self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : [UIColor whiteColor]}

To change your Status bars text color to white add this to your view

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
like image 25
Rich86man Avatar answered Sep 30 '22 10:09

Rich86man