UIBarButtonItem:如何为突出显示的状态设置外观

时间:2014-03-05 17:53:31

标签: ios uibarbuttonitem

我有一个UIBarButtonItem的图像,但我不想显示突出显示的状态。现在,当按下按钮时,我的图像会变灰。我尝试为突出显示的状态设置相同的图像,但没有做任何事情。

由于

1 个答案:

答案 0 :(得分:0)

试试我的朋友:

https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/adjustsImageWhenHighlighted

设置按钮

adjustImageWhenHighlighted = NO;

应该这样做。

希望它有所帮助。干杯

<强>更新

// Initialize the UIButton
UIButton *customButton= [UIButton buttonWithType:UIButtonTypeCustom];

//normal_button.png and selected_button.png need to be created by you
[customButton setBackgroundImage: [UIImage imageNamed:@"normal_button.png"] forState:UIControlStateNormal];
[customButton setBackgroundImage: [UIImage imageNamed:@"normal_button.png"] forState:UIControlStateSelected];

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView: customButton];

另一种方法。