我有一个自定义单元格,其中包含一些 UIButton。我在按钮上创建了这样的目标操作:
[cell.customLocationButton addTarget:self action:@selector(customLocationButtonTap:) forControlEvents:UIControlEventTouchUpInside];
虽然我没有在 UIButtons 上看到默认的 iOS 淡入淡出动画,但这些操作效果很好吗?我是否也需要启用某些功能才能获得这些功能 - 我认为在使用 IB 的 UIButton 时它们是标准配置?
最佳答案
遇到了同样的问题。我可以使用 setTitleColor:forState:
让按钮在突出显示时更改颜色,但它并没有像其他系统按钮那样从突出显示淡出到正常状态。
原来那是因为我的按钮是 UIButtonTypeCustom
类型。将它切换到 UIButtonTypeSystem
为我解决了这个问题。请注意我在 iOS9 上运行它。
这是一个片段 (Swift),它假设 self
是一个 UIView
或子类:
let button = UIButton(type: .System)
button.setTitle("Title", forState: .Normal)
button.sizeToFit() // Sizes the button frame based on the title.
addSubview(button)
关于ios - UITableViewController 自定义单元格中缺少 UIButton 默认点击淡入淡出动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489416/