状态栏中的背景文本仍然是黑色的。如何将颜色更改为白色?
// io8, swift, Xcode 6.0.1 override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBar.barTintColor = UIColor.blackColor() self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()] }
在 AppDelegate.swift ,在application(_:didFinishLaunchingWithOptions:)我放了以下内容:
AppDelegate.swift
application(_:didFinishLaunchingWithOptions:)
UINavigationBar.appearance().barTintColor = UIColor(red: 234.0/255.0, green: 46.0/255.0, blue: 73.0/255.0, alpha: 1.0) UINavigationBar.appearance().tintColor = UIColor.white UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
(对于 Swift 4 或更早的版本NSAttributedStringKey,而不是NSAttributedString.Key)
NSAttributedStringKey
NSAttributedString.Key
对于titleTextAttributes,文档说:
titleTextAttributes
您可以在文本属性字典中为标题指定字体、文本颜色、文本阴影颜色和文本阴影偏移量