我如何去改变UINavigationBar在Swift中的颜色?
@H_502_1@大多数在线的东西说做类似的事情:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];@H_502_1@我翻译成了
let titleDict: NSDictionary = ["NSForegroundColorAttributeName": UIColor.whiteColor()] self.navigationController.navigationBartitleTextAttributes = titleDict //self is referring to a UIViewController@H_502_1@但它不工作。我已经改变了背景和按钮颜色,但文字颜色不会改变。有任何想法吗?
使用NSForegroundColorAttributeName作为键,而不是“NSForegroundColorAttributeName”字符串。
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()] self.navigationController.navigationBar.titleTextAttributes = titleDict