UITableViewController自定义单元中缺少UIButton默认的点击淡入淡出动画 [英] UIButton default tap fade animation missing in UITableViewController custom cell
问题描述
我有一个带有几个UIButton的自定义单元格.我已经在按钮上创建了目标操作":
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];
尽管我没有在UIButton上看到默认的iOS淡入淡出动画,但这些动作效果很好.我也需要启用某些功能来获得这些功能吗-我认为使用IB的UIButton时它们是标准的吗?
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?
推荐答案
出现相同的问题.我可以使用setTitleColor:forState:
来更改突出显示上的颜色的按钮,但是它没有像其他系统按钮一样从突出显示退回到正常状态.
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.
原来是因为我的按钮的类型是UIButtonTypeCustom
.将其切换为UIButtonTypeSystem
可以为我解决.请注意,我正在iOS9上运行它.
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.
以下是一个片段( Swift ),其中假定self
是UIView
或子类:
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)
这篇关于UITableViewController自定义单元中缺少UIButton默认的点击淡入淡出动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!