Swift 设置导航栏的标题和颜色

搜到的答案都是这种:

self.navigationController?.navigationBar.titleTextAttributes=[NSForegroundColorAttributeName:UIColor.orange, NSFontAttributeName : UIFont.systemFont(ofSize: 25) ]

但程序报错:

Use of unresolved identifier 'NSForegroundColorAttributeName'

目前正确写法应该是:

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.orange,

                                                  NSAttributedStringKey.font : UIFont.systemFont(ofSize: 25)]

猜你喜欢

转载自blog.csdn.net/weixin_42012181/article/details/82112986