我正在使用像这样的布尔值来改变我的按钮图像,但是我有几个问题:
@IBOutlet weak var checkedButtonOutl: UIButton!
var hasBeenTouched = false
override func viewDidLoad() {
super.viewDidLoad()
checkedButtonOutl.setImage(uncheckedImage, forState: UIControlState.Normal)
checkedButtonOutl.addTarget(self, action: "click", forControlEvents: UIControlEvents.TouchUpInside)
checkedButtonOutl.showsTouchWhenHighlighted = false
}
func click(){
if hasBeenTouched == false{
checkedButtonOutl.setImage(uncheckedImage, forState: UIControlState.Normal)
hasBeenTouched = true
}else{
checkedButtonOutl.setImage(checkedImage, forState: UIControlState.Normal)
hasBeenTouched = false
视图加载后,您必须在更改之前触摸按钮两次。此外,当触摸按钮时,它突出显示,我不想要,我认为showsTouchWhenHighlighted
功能会处理。
如何解决这两个问题的任何建议都将不胜感激。