UIButton default tap fade animation missing in UITableViewController custom cell

Viewed 11943

I have a custom cell with a few UIButtons in it. I have created Target Actions like so on the buttons:

[cell.customLocationButton addTarget:self action:@selector(customLocationButtonTap:) forControlEvents:UIControlEventTouchUpInside];

The actions work great though I don't see the default iOS fade animation on the UIButtons? Is there something I need to enable to get those too - I thought they were standard when using a UIButton from IB?

6 Answers

I found this solution:

setTitleColor(UIColor.init(white: 1, alpha: 0.3), for: .highlighted)

It's really simple and works perfectly.

you probably initialized the button like this:

let button = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: <width>, height: <height>)

try to do it like this:

let button = UIButton.init(type: .system)
button.frame = CGRect.init(x: 0, y: 0, width: <width>, height: <height>)

The "fade" animation on tap, comes with system style, after init the button you can customize it.

Related