質問

I have an image for a UIBarButtonItem but I do not want the highlighted state to show. Right now my image gets greyed out when the button is pressed. I tried to set the same image for the highlighted state but that didn't do anything.

Thanks

役に立ちましたか?

解決

Try this my friend:

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

setting the buttons

adjustImageWhenHighlighted = NO;

should do the trick.

Hope it helps. Cheers

UPDATE:

// 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];

Another way to do this.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top