UIButton default tap fade animation missing in UITableViewController custom cell

后端 未结 6 932
后悔当初
后悔当初 2021-02-08 08:41

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         


        
6条回答
  •  遥遥无期
    2021-02-08 09:10

    I've been searching all over the internet and finally I've found a solution from a post on StackOverFlow check it out here.

    For Swift 4 You can add this UIButton extension and it will work fine.

    extension UIButton {
    
        override open func touchesBegan(_ touches: Set, with event: UIEvent?) {
            isHighlighted = true
            super.touchesBegan(touches, with: event)
        }
    
        override open func touchesEnded(_ touches: Set, with event: UIEvent?) {
            isHighlighted = false
            super.touchesEnded(touches, with: event)
        }
    
        override open func touchesCancelled(_ touches: Set, with event: UIEvent?) {
            isHighlighted = false
            super.touchesCancelled(touches, with: event)
        }
    
    }
    

提交回复
热议问题