Programmatically disable click selection UIButton

There must be a way to do this, but I cannot find it. I have a button that I 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 a button so as not to highlight or change the appearance in any way when it touches. So far, I tried when creating a 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 works.

+8
ios objective-c uibutton
source share
4 answers

Make your custom UIButton button and then apply a UIImage background to it. It will not stand out or change when pressed

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
+9
source share

You can simply set adjustImageWhenHighlighted to No.

 button.adjustsImageWhenHighlighted = NO; 
+12
source share

Bro, I tried different ways, like you. But finally, our own recipe found:

I do not know how this works with a custom button with UIImage on it but for a simple UIButton with text for the highlighted state. You just need to set the same settings as in the default state.

And for the selected state, a space is set for the image property in IB. You may find that sometimes a button may have a strange bias when you click on it. In this case, remove the text from the text box for the selected state. He will solve this problem.

enter image description here

Then on your click event, you will see that it is not blinking at all.

+6
source share

For those using a custom PNG image with the hue color turned on, you can avoid blackout (e.g., from white to gray) with this code:

  clearButton.tintAdjustmentMode = UIViewTintAdjustmentModeNormal; 
0
source share

All Articles