UIButton default tap fade animation missing in UITableViewController custom cell

后端 未结 6 936
后悔当初
后悔当初 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:06

    Had the same problem. I could get the button to change color on highlight with setTitleColor:forState:, but it didn't fade from highlight to normal state like the other system buttons.

    Turns out that's because my button was of type UIButtonTypeCustom. Switching it to UIButtonTypeSystem solved it for me. Please note I'm running this on iOS9.

    Here's a snippet (Swift) that assumes self is a UIView or subclass:

    let button = UIButton(type: .System)
    button.setTitle("Title", forState: .Normal)
    button.sizeToFit() // Sizes the button frame based on the title.
    addSubview(button)
    

提交回复
热议问题