我试图改变设置按钮的颜色为白色,但不能让它改变。

这两种方法我都试过:

navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()

但没有变化,它看起来仍然是这样的:

我怎么把那个按钮变成白色?


当前回答

斯威夫特3

被点赞最多的答案是Swift 3不正确。

改变颜色的正确代码是:

self.navigationController?.navigationBar.tintColor = UIColor.white

如果你想改变颜色,改变UIColor。白色以上到所需的颜色

其他回答

它将通过-(void)viewDidLoad中的这一行来解决:

self.navigationItem.backBarButtonItem.tintColor = UIColor.whiteColor;

斯威夫特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)

斯威夫特

 override func viewDidLoad() {
     super.viewDidLoad()

 self.navigationController?.navigationBar.tintColor = UIColor.white
 }

出于某种原因,它在编程上不适合我。但是,在故事板中设置它每次都有效。

self.navigationController?.navigationBar.tintColor = UIColor.redColor()

这段代码具有魔力。而不是红色,改变它作为你的愿望。