状态栏中的背景文本仍为黑色 . 如何将颜色更改为白色?
// io8, swift, Xcode 6.0.1
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()]
}
13 回答
在 AppDelegate.swift 中,在
application(_:didFinishLaunchingWithOptions:)
中我提出以下内容:对于
titleTextAttributes
,docs说:我喜欢亚历克斯的回答 . 如果你想快速尝试一下
ViewController
确保你使用要普遍改变颜色,此代码应位于
NavigationController
的viewDidLoad
函数中:要根据
ViewController
进行更改,您必须从ViewController
引用NavigationController
并在ViewController
的viewWillAppear
函数中写入类似的行 .//在Swift 4中
要在 objective-c 中工作,我必须在
viewWillAppear
中将以下行放在我的CustomViewController中 .对于 Swift2.x 这适用:
对于 Swift3.x ,这有效:
To do this job in storyboard (Interface Builder Inspector)
在
IBDesignable
的帮助下,我们可以为Interface Builder Inspector添加更多选项UINavigationController
并在故事板上调整它们 . 首先,将以下代码添加到项目中 .然后只需在storyboard上设置UINavigationController的属性 .
如果要为整个应用程序设置色调颜色和条形颜色,可以将以下代码添加到AppDelegate.swift中
Navigation barTintColor and tintColor is set
更新了swift 4
在Swift 4.1和Xcode 9.4.1中
斯威夫特4
Swift 4.1
将一个func添加到viewDidLoad
在
setup()
函数中添加:在Swift 3中,这适用于:
对于
TitleText
TitleText
的自定义颜色,这里是Swift 3的简单和简短代码:要么