Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Disable Highlight on Click of UIButton

There must be a way to do this, but I can't find it. I have a button I have created programmatically:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(25, self.view.frame.size.height/4, 200, 350);
[button setTitle:@"Inbox" forState:UIControlStateNormal];
[button addTarget:self action:@selector(popViewController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

All I want is for the button not to highlight or change in appearance in any way when it is touched. So far I have tried the following when creating the button:

[button setBackgroundImage:[UIImage imageNamed:nil] forState:UIControlStateSelected | UIControlStateHighlighted];

AND

[button setBackgroundImage:nil forState:UIControlStateSelected];

AND

[button setAdjustsImageWhenHighlighted:NO];

AND

button.showsTouchWhenHighlighted = NO;

Then in the button action I tried:

[sender setHighlighted:!sender.isHighlighted];

AND

[sender setSelected:!sender.isSelected];

None of these work.

like image 211
jac300 Avatar asked Jul 10 '13 20:07

jac300


1 Answers

You can just simply set adjustImageWhenHighlighted to No.

button.adjustsImageWhenHighlighted = NO;
like image 74
Warut Surapat Avatar answered Oct 08 '22 10:10

Warut Surapat