【发布时间】:2017-06-27 09:43:51
【问题描述】:
我正在尝试在我的应用 (iOS 9+) 中更改导航栏上的 backBarButtonItem 的颜色。
我可以这样做:
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
但这会改变导航栏上所有 UIBarButtonItems 的颜色,我只想改变后退按钮。
我试过了:
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
和
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
但它不起作用
注意:我想保留系统后退按钮的
【问题讨论】:
-
如果可能,您可以使用自定义视图
-
@MikeAlter 是对的,我们可以使用自定义视图 UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:yourUIButton]
-
没有办法只改变导航栏上特定栏按钮项的颜色吗?
-
尝试在
viewWillAppear中更改颜色。这个对我有用!在 VC 1self.navigationController?.navigationBar.tintColor = UIColor.red和 VC 2self.navigationController?.navigationBar.tintColor = UIColor.white中分别给出红色和白色的返回按钮。 -
回答前请阅读我的问题
标签: ios iphone uinavigationcontroller uinavigationbar uinavigationitem