[英]UIButton not going changing text color when there is long-press gesture recognizer
我有以下代码:
deleteAllButton.setTitle("Delete", forState: .Normal)
deleteAllButton.titleLabel?.numberOfLines = 2
deleteAllButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
deleteAllButton.titleLabel?.font = UIFont.systemFontOfSize(keyboardFontSize)
// deleteAllButton.addTarget(self, action: #selector(deletekeyPressed), forControlEvents: .TouchUpInside)
let deleteLPGR = UILongPressGestureRecognizer(target: self, action: #selector(deleteButtonLongPress))
deleteLPGR.minimumPressDuration = 0
deleteLPGR.delaysTouchesBegan = true
deleteAllButton.addGestureRecognizer(deleteLPGR)
通常,当按下UIButton时,文本会自动更改颜色以指示其处于“按下”状态。 但是,由于我添加了长按手势识别器,因此该按钮并不表示该按钮处于“按下”状态。
我如何仍然允许触摸事件传递给按钮,使用户感觉按钮实际上被“按下”?
我认为您不需要添加手势识别器。
只是尝试为突出显示的状态设置titlecolor,它应该可以工作
deleteAllButton.setTitleColor(UIColor.redColor(), forState: .Highlighted)
希望这能解决您的问题。
只需将deleteLPGR.minimumPressDuration = 0
更改为deleteLPGR.minimumPressDuration = 1
然后按一下即可注意到颜色变化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.