【发布时间】:2020-09-09 23:38:10
【问题描述】:
我有一个 UIButton,点击它会使背景图像在 OFF 和 ON 图像之间切换。
我将这两个图像定义为:
let offPosition = UIImage(named:"Dont Send.pdf")! as UIImage
let onPosition = UIImage(named:"send Button.pdf")! as UIImage
在我声明的视图控制器中:
var smsButtonActive = false
按钮有一个出口:
@IBOutlet weak var smsButton: PeControlButton!
我已将按钮单击定义为:
@IBAction func smsButtonClick(_ sender: PeControlButton){
if smsButtonActive {
smsButton.setBackgroundImage(onPosition, for: .normal)//on position
appSettings.set(smsButtonActive, forKey: "sendText")//writes status to appSettings
}else {
smsButton.setBackgroundImage(offPosition, for: .normal)//off position
appSettings.set(smsButtonActive, forKey: "sendText")//writes status to appSettings
}
smsButtonActive = !smsButtonActive
}
我的问题是,如果开关位置从 On 位置开始,则需要单击一下来更改图像。如果它从关闭位置开始,我必须双击才能更改图像。我知道这不是一场大戏,因为图像发生了变化,但如果有人能指出正确的方向,我想深入了解它。
【问题讨论】: