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

这两种方法我都试过:

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

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

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


当前回答

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

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

其他回答

如果你在Settings视图控制器中已经有了后退按钮,你想改变Payment Information视图控制器上后退按钮的颜色为其他颜色,你可以在Settings视图控制器的prepareforsegue中这样做:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "YourPaymentInformationSegue"
    {
        //Make the back button for "Payment Information" gray:
        self.navigationItem.backBarButtonItem?.tintColor = UIColor.gray               
    }
}

在AppDelegate类中使用此代码,在didFinishLaunchingWithOptions中。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

UINavigationBar.appearance().tintColor = .white

}

这段代码更改箭头的颜色

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 =

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

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

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