35
votes

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;
11
Wow, just tried all of these answers on a custom button and could get none of them to work. - Tim MB

11 Answers

128
votes

I had this same issue and I resolve it by changing the UIButton type from "System" to "Custom". The blue background color does not show up in selected state when it is a "Custom" type.

19
votes

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];
}
9
votes

Change the alpha of the tintColor to zero, works if iOS is 5.0 or later

UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];  
button.tintColor = color;
7
votes

Very simple, in storyBoard, select your UIButton and open attribute inspector. Now scroll down to View section and change Tint property to Clear Color or any specific color if u want.

enter image description here

5
votes

UIButton also with custom type, we can set it in xcode as-

enter image description here

OR By programmatically as-

 let customButton = UIButton(type: .custom) 
  customButton.setTitle("this is Button", for: .normal)
  customButton.setTitleColor(UIColor.blue, for: .normal)
  customButton.frame = CGRect(x: 15, y: 50, width: 300, height: 500)
            self.view.addSubview( customButton)

Now there is no more UIButton's blue background color

2
votes

Not a direct answer to OP's question but to remove this colour in a UIButton subclass you can do this:

override func layoutSubviews() {
    tintColor = .clear
    super.layoutSubviews()
}
1
votes

What did it for me was changing the button.tintColor in the highlighted state. This is swift 3, iOS 10

override public var isHighlighted: Bool {
    didSet {
        self.tintColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)
    }
}

Or you can do the same in the interface builder

Choose button state

Choose button tint color

1
votes

Changed UIButton type to Custom in IB worked for me.

0
votes

Swift Version

extension UIButton {
    override public var highlighted: Bool {
        didSet {
            // clear background color when selected
            self.layer.backgroundColor = .None
        }
    }
}
-2
votes

Use...

    [myButton setAdjustsImageWhenHighlighted:FALSE];
-2
votes

Not sure if this is the best way. But you could have an invisible button or view ontop of the actual button then recognize when the top button/view has been clicked.