ios - 如何保持 UIButton 突出显示直到第二次触摸?

标签 ios xcode swift cocoa-touch uibutton

我想将按钮保持在突出显示状态图像直到第二次触摸以将其释放到正常状态。

我试过dispatch_async方法,但是再点击一次就无法恢复到正常状态。

(我在 Swift 中编码,所以 performSelector:WithObject 方法也不起作用。)

最佳答案

我将使用选中状态而不是突出显示。 UIButton 已有该属性,因此您无需创建任何其他属性。

button.setImage(image, forState: UIControlState.Normal)
button.setImage(selectedImage, forState: UIControlState.Selected)

button.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)


func buttonTapped(sender:UIButton)
{
  sender.selected = !sender.selected;
}

关于ios - 如何保持 UIButton 突出显示直到第二次触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30799413/

相关文章:

ios - 如何在 iOS 8 的模态视图 Controller 中强制纵向显示?

android - Messenger InstantGames - Web 请求在 Messenger 网页上运行良好,但在通过 Messenger 移动应用程序播放时失败

ios - 由于信息 plist 中的版本无效,XCode 无法验证

swift - Swift 中的元组和函数参数

ios - 使用 Parse 数据库填充表

ios - 最轻的 UI 元素

ios - 如何获取/查看 iOS 应用程序的崩溃报告

objective-c - 启动画面不显示在 iPad 上,但显示在模拟器上

ios - 如何在 Swift 中设置右 UIBarButtonItem 的色调颜色?

ios - UITapGestureRecognizer 无法识别的选择器发送到实例