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

这两种方法我都试过:

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

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

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


当前回答

在Swift3中,将后退按钮设置为红色。

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

其他回答

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

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

你应该这样使用:

navigationController?.navigationBar.barTintColor = .purple
navigationController?.navigationBar.tintColor = .white

在Swift 4中,你可以使用以下方法来解决这个问题:

let navStyles = UINavigationBar.appearance()
// This will set the color of the text for the back buttons.
navStyles.tintColor = .white
// This will set the background color for navBar
navStyles.barTintColor = .black

斯威夫特3

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

改变颜色的正确代码是:

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

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

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

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