Change color of UINavigationController back button

时光毁灭记忆、已成空白 提交于 2019-12-31 03:27:12

问题


I'm having problems trying to figure out how to change the color of the buttons on the navigation controller.

Previously I had used the following:

[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:226/255.0 green:66/255.0 blue:66/255.0 alpha:0.0]];

and this worked, but I added a new view with a toolbar, and the tool bar button images will not show. If I remove the global coloring, the tool bar items show just fine.

I've tried setting the tint color on both the leftBarButtonItem and the backBarButtonItem in the viewDidLoad method of the view, but both of those properties appear to be null.

I don't want to change the color of the entire navigation bar, just the buttons. Is there a way to do this?


回答1:


Yeah, I'll just post this as an answer. Your alpha is set to 0. So you're basically saying the same thing as [UIColor clearColor]. Not sure how that ever worked to give you a tint color on your bar button items.




回答2:


In swift, it can be accomplished by the following command:

if let navController = self.navigationController
{
    navController.navigationBar.tintColor = UIColor.whiteColor()
}


来源:https://stackoverflow.com/questions/12593065/change-color-of-uinavigationcontroller-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!