How to change background color of UINavigationItem?

后端 未结 4 1557
-上瘾入骨i
-上瘾入骨i 2021-01-04 07:03

I have a UINavigationItem, but I can\'t found anything beside tittle, prompt, and back button in attribute inspector

4条回答
  •  醉酒成梦
    2021-01-04 07:49

    You shouldn't use the background property of UINavigationBar, but instead you should use barTintColor like this:

    self.navigationController.navigationBar.barTintColor = UIColor.redColor()
    

    As written in the official documentation to change the bar background you have to access to the barTintColor property:

    The tint color to apply to the navigation bar background.
    

    If you want to edit the style of the navigation bar such as button color you should access to the barTint property. If you want to edit the style of an navigationItem such as back button you should edit the button property, not the UINavigationItem's.

提交回复
热议问题