Swift中的UINavigationBar文本颜色 [英] UINavigationBar Text Color in Swift
本文介绍了Swift中的UINavigationBar文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Swift中更改UINavigationBar
的颜色?
How would I go about changing the color of the UINavigationBar
in Swift?
大多数在线事情都说要做类似的事情:
Most things online say to do something like:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
我翻译为
let titleDict: NSDictionary = ["NSForegroundColorAttributeName": UIColor.whiteColor()]
self.navigationController.navigationBartitleTextAttributes = titleDict
//self is referring to a UIViewController
但是它不起作用.我已经更改了背景和按钮的颜色,但是文本的颜色没有改变.有什么想法吗?
But it doesn't work. I already changed the background and button colors, but the text color doesn't change. Any ideas?
推荐答案
使用NSForegroundColorAttributeName
作为键,而不是"NSForegroundColorAttributeName"
字符串.
Use NSForegroundColorAttributeName
as key, not "NSForegroundColorAttributeName"
string.
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController.navigationBar.titleTextAttributes = titleDict
这篇关于Swift中的UINavigationBar文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文