Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change pressed color of UIButton [duplicate]

Tags:

ios

uibutton

Is there any way to change the color of a UIButton when it's pressed?

The default seems to be a blue color, but I don't see where or how to change this to a custom color.

Thanks!

like image 514
Sandy Avatar asked Jun 21 '13 04:06

Sandy


2 Answers

If you are using storyboard then in inspector window you can change the highlight tint property to the color you want on button click event.

highlight tint

Look at the Highlight Tint property in image.

like image 96
Geek Avatar answered Oct 11 '22 12:10

Geek


I ultimately followed the following poster's suggestion. It worked perfectly.

https://stackoverflow.com/a/10670141/720175

In my particular case I created a subclass of UIButton, with the final code as:

-(void) setHighlighted:(BOOL)highlighted
{
    if(highlighted) {
        self.backgroundColor = [UIColor colorWithRed:1 green:0.643 blue:0.282 alpha:1];
    } else {
        self.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    }
    [super setHighlighted:highlighted];
}

Easy as pie.

like image 30
Sandy Avatar answered Oct 11 '22 14:10

Sandy