我试图改变设置按钮的颜色为白色,但不能让它改变。
这两种方法我都试过:
navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但没有变化,它看起来仍然是这样的:
我怎么把那个按钮变成白色?
我试图改变设置按钮的颜色为白色,但不能让它改变。
这两种方法我都试过:
navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()
但没有变化,它看起来仍然是这样的:
我怎么把那个按钮变成白色?
当前回答
你应该加上这一行
self.navigationController?.navigationBar.topItem?.backBarButtonItem?.tintColor = .black
其他回答
你只有一个选择把你的后退按钮藏起来,用你自己来做。 然后设置它的颜色。
我这样做了:
self.navigationItem.setHidesBackButton(true, animated: true)
let backbtn = UIBarButtonItem(title: "Back", style:UIBarButtonItemStyle.Plain, target: self, action: "backTapped:")
self.navigationItem.leftBarButtonItem = backbtn
self.navigationItem.leftBarButtonItem?.tintColor = UIColor.grayColor()
让我们试试这段代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = UIColor.whiteColor() // Back buttons and such
navigationBarAppearace.barTintColor = UIColor.purpleColor() // Bar's background color
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] // Title's text color
self.window?.backgroundColor = UIColor.whiteColor()
return true
}
self.navigationController?.navigationBar.tintColor = UIColor.black // to change the all text color in navigation bar or navigation
self.navigationController?.navigationBar.barTintColor = UIColor.white // change the navigation background color
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black] // To change only navigation bar title text color
斯威夫特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)
在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