Swift 中的 UINavigationBar 文本颜色 [英] UINavigationBar Text Color in Swift

查看:17
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆