xcoder
xcoder

Reputation: 1436

How can I prevent a UIButton from highlighting when pressed?

When an UIButton is pressed, the normal situation is that it will be highlighted i.e. a shadow like layer will cover the image. Is there a way to prevent this from happening? Is there an attribute to handle this?

Upvotes: 6

Views: 4032

Answers (3)

Matt Becker
Matt Becker

Reputation: 2368

You can also achieve this through Interface Builder. Uncheck "Highlighted Adjusts Image" in the Attributes inspector.

enter image description here

Upvotes: 4

Will Larche
Will Larche

Reputation: 3149

If you make a custom subclass of the UIButton you can override setHighlighted:(BOOL)highlighted to do nothing

- (void)setHighlighted:(BOOL)highlighted
{ 
    return;
}

Upvotes: 5

Johan Kool
Johan Kool

Reputation: 15927

You normally don't press a button with Xcode, you use your finger (or mouse). But nitpicking aside: adjustsImageWhenHighlighted set to NO will do the trick.

Upvotes: 11

Related Questions