更改iOS 11大标题颜色
我在iOS 11中使用新的扩大的导航栏标题。但我似乎无法更改textColor。
我试过了:
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
这没有做任何事情。 有任何想法吗?
self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
我认为这仍然是Xcode 9 beta 6中的一个bug。
我发现了不同的“解决scheme”:
- 如果你把它放在AppDelegate中,可以改变标题的颜色:
如果#可用(iOS 11.0,*){ UINavigationBar.appearance()。largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.blue] }
- 其他的方法是在控制器的viewDidLoad中设置颜色,但使其工作的秘诀就是设置字体:
如果#可用(iOS 11.0,*){ self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.blue,NSAttributedStringKey.font:UIFont.systemFont(ofSize:31,weight:UIFont.Weight.bold)] }
希望它可以帮助你。
问候!