Search code examples
iosobjective-ciphoneuibuttonuikit

How to remove UIButton selected background color?


I am looking for a solution to this problem that does NOT require using images/PNGs. I am looking for a way to remove the UIButton's blue background color when it's in selected state, and I just cannot find a way to do that without using images. I am basically trying to do something like that in case of a UITableViewCell:

   cell.selectionStyle = UITableViewCellSelectionStyleNone;

Solution

  • Unfortunately I'm away from my test machine at the moment, but there are two things you could try.

    First would be to set the following property:

    button.adjustsImageWhenHighlighted = NO;
    

    Or uncheck "Highlight adjusts image" in Interface Builder.

    If that doesn't work like you expect it to, you can deselect the button in the action you tied it to, like so:

    - (IBAction)yourButtonAction:(id)sender {
        [sender setHighlighted:NO];
    }