swift navigation title 标题颜色代码设置

文章目录

简单记录,为后续方便查找,仅有代码片段
可以放在ViewController的基类中

 1if let bar = self.navigationController?.navigationBar {
 2    bar.backgroundColor = .themeColor
 3    bar.tintColor = .white
 4    var attrs = bar.titleTextAttributes
 5    if attrs == nil {
 6        attrs = [NSAttributedStringKey:Any]()
 7    }
 8    attrs?[NSAttributedStringKey.foregroundColor] = UIColor.white
 9    bar.titleTextAttributes = attrs
10}