ios - UITableViewController 自定义单元格中缺少 UIButton 默认点击淡入淡出动画

标签 ios iphone objective-c uitableview uibutton

我有一个自定义单元格,其中包含一些 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/

相关文章:

ios - 在 UILabel 中显示分数

iphone - Apple iOS 是否支持向后兼容?

iphone - GPS不会停止更新

ios - Collection View 中的水平滚动

iphone - 如何获得图层点?

ios - 如何为快速播放的声音添加延迟

iphone - UIImageView 带有大图像。问题

ios - 出现键盘时如何向上移动 UIScrollView?

ios - 错误 "int1"无法转换为 'Bool' swift3

ios - 如何在 UITableView 中高效加载图片?