我试图改变设置按钮的颜色为白色,但不能让它改变。
这两种方法我都试过:
navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但没有变化,它看起来仍然是这样的:
我怎么把那个按钮变成白色?
我试图改变设置按钮的颜色为白色,但不能让它改变。
这两种方法我都试过:
navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但没有变化,它看起来仍然是这样的:
我怎么把那个按钮变成白色?
当前回答
在故事板中很容易设置:
其他回答
出于某种原因,它在编程上不适合我。但是,在故事板中设置它每次都有效。
你应该这样使用:
navigationController?.navigationBar.barTintColor = .purple
navigationController?.navigationBar.tintColor = .white
斯威夫特5.5
更改完整的应用程序主题
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set for app
UINavigationBar.appearance().tintColor = .white
return true
}
更改特定控制器
let navController = UINavigationController.init(rootViewController: yourViewController)
navController.navigationBar.tintColor = .red
present(navController, animated: true, completion: nil)
你应该加上这一行
self.navigationController?.navigationBar.topItem?.backBarButtonItem?.tintColor = .black
这段代码更改箭头的颜色
self.navigationController.navigationBar.tintColor = UIColor.whiteColor();
如果这不起作用,请使用下面的代码:
self.navigationBar.barStyle = UIBarStyle.Black
self.navigationBar.tintColor = UIColor.whiteColor()
Swift 3 Notes
UIColor.whiteColor()和类似的被简化为UIColor.white
此外,许多以前的隐式可选项已被更改为显式,因此您可能需要:
self.navigationController?.navigationBar =