Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change iOS 11 large title color

I'm using the new enlarged navigation bar titles in iOS 11. But I can't seem to be able to change the textColor.

I tried doing:

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

This didn't do anything. Any ideas?

like image 356
user4992124 Avatar asked Jun 29 '17 10:06

user4992124


3 Answers

I think it's still a bug in Xcode 9 beta 6.

I found different "solutions" for it:

  1. It's possible to change the color of the title if you put this in the AppDelegate:
    if #available(iOS 11.0, *) {
      UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue]
    }
  1. Other way is to set the color in your Controller's viewDidLoad, but the secret to make it work is to set the font also:
    if #available(iOS 11.0, *) {            
      self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 31, weight: UIFont.Weight.bold) ]
    }

Hope it helps you.

Regards!

like image 200
Kevin Furman Avatar answered Nov 16 '22 00:11

Kevin Furman


self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; 
like image 34
David Knight Avatar answered Nov 15 '22 22:11

David Knight


iOS 11

enter image description here

Objective-C

if (@available(iOS 11.0, *)) {
    self.navigationController.navigationItem.largeTitleDisplayMode =  UINavigationItemLargeTitleDisplayModeAlways;
    self.navigationController.navigationBar.prefersLargeTitles = true;

// Change Color
    self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

} else {
    // Fallback on earlier versions
}
like image 40
Vivek Avatar answered Nov 16 '22 00:11

Vivek