如何在UIBar按钮上更改突出显示状态下的颜色?

时间:2014-11-16 22:02:56

标签: ios objective-c uibarbuttonitem

我希望在高亮状态下更改我的UIBarButton的颜色,但我无法让它工作。现在我使用setTintColor设置颜色,这设置了我的栏的颜色。

[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:108/255.0f green:108/255.0f blue:108/255.0f alpha:1.0f]];

但是当我尝试更改突出显示状态的颜色时,它不起作用,这就是我正在尝试的。

[[UIBarButtonItem appearance] setTitleTextAttributes:[UIColor colorWithRed:122/255.0f green:122/255.0f blue:122/255.0f alpha:1.0f] forState:UIControlStateHighlighted];

有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

试试这个,

[myButton setBackgroundImage:[self imageWithColor:[UIColor colorWithRed:122/255.0f green:122/255.0f blue:122/255.0f alpha:1.0f]] forState:UIControlStateHighlighted];

这可能对您有所帮助