views:

887

answers:

3

I've got a UIButton that, when selected, shouldn't change state when being touched. The default behaviour is for it to be in UIControlStateHighlighted while being touched, and this is making me angry.

Suggestions?

+2  A: 

In IB you can uncheck "highlight adjusts image"

Haydn
Any chance you know what the programmatic version of this would be?Right now I've got it working hackishly by making it disabled, and dressing it up as being selected.
Kelso.b
uibutton.adjustsImageWhenHighlighted = NO;
Haydn
A: 

Depending on what changes from the default to the highlighted state of the button, you can call a couple of methods to set them to what you need. So if the image changes you can do

[myButton setImage:[myButton imageForState:UIControlStateNormal] forState:UIControlStateHighlighted];

If the text changes you can do

[myButton setTitle:[myButton titleForState:UIControlStateNormal] forState:UIControlStateHighlighted];

other similar functions:

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state

- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state

Dimitris
A: 

Hola,

OK here's an easy solution if this works for you, after a week of banging my head on this it finally occurred to me to just set highlighted=NO for the 1st line of the IBAction method for the TouchUpInside or TouchDown, or whatever works. For me it was fine on the TouchUpInside.

-(IBAction)selfDismiss:(id)sender {

    self.btnImage.highlighted = NO;

    NSLog(@"selfDismiss");

    etc, etc, etc.

}
therealbuckley