之前的Swift问题记录,感觉有点长了,看着特别累,现在就遇到的知识点一点一点记录好了
<span style="font-family:Comic Sans MS;font-size:24px;">// 1、获取导航条
let navBar = UINavigationBar.appearance();
// 2、设置导航条背景
navBar.setBackgroundImage(UIImage(named: "xxxx"), forBarMetrics: UIBarMetrics.Default);
// 3、设置字体属性
var attributes = NSMutableDictionary();
attributes.setValue(UIColor.whiteColor(), forKey: NSForegroundColorAttributeName);
navBar.titleTextAttributes = attributes;</span>
之所以在这里做记录,是因为Q群中有些朋友,在NavigationBar上放了层UIView,设置相同的颜色,当时我也很屌丝,也就信以为真……
另一个记录原因是设置字体属性的时候,key设置为UITextAttributeTextColor死活没反应,最后根据错误提示信息才换成NSForegroundColorAttributeName。