who*_*cow 9 iphone objective-c uibutton uitableview ios
我有一个自定义单元格,里面有几个UIButton.我在按钮上创建了类似的目标操作:
[cell.customLocationButton addTarget:self action:@selector(customLocationButtonTap:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
尽管我没有在UIButtons上看到默认的iOS淡入淡出动画,但这些动作效果很好?是否有我需要启用的东西 - 我认为它们是使用IB的UIButton时的标准?
有同样的问题。我可以使用按钮更改突出显示上的颜色setTitleColor:forState:
,但是它没有像其他系统按钮一样从突出显示淡入正常状态。
原来是因为我的按钮是type 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)
Run Code Online (Sandbox Code Playgroud)
小智 6
我一直在互联网上搜索,最后我从 StackOverFlow 上的帖子中找到了解决方案,请在此处查看。
对于 Swift 4,您可以添加此 UIButton 扩展,它会正常工作。
extension UIButton {
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = true
super.touchesBegan(touches, with: event)
}
override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = false
super.touchesEnded(touches, with: event)
}
override open func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
isHighlighted = false
super.touchesCancelled(touches, with: event)
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5576 次 |
最近记录: |