swift5导航栏标题文字属性设置
在oc里面想必大家都非常熟悉,那么在swift5里面,怎么设置导航栏标题的文字呢. 先看oc。
self.navigationItem.title = @"首页";
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName: UIColor.redColor,
NSFontAttributeName: [UIFont systemFontOfSize:26 weight:UIFontWeightUltraLight]
};
[self.navigationController.navigationBar setBackgroundColor:UIColor.systemGray4Color];
swift5 写法:
self.title = "首页"
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red,NSAttributedString.Key.font: UIFont.systemFont(ofSize: 25, weight: .ultraLight)]
self.navigationController?.navigationBar.backgroundColor = UIColor.systemGray4
重点是NSAttributedString.Key.font这个写法:
|