我有5个不同的按钮,我希望用户能够选择一个,如果它没有被选中,并取消选择它,如果它已被选中,同时如果选择了另一个按钮则取消选择。按钮不会更改用户进入主屏幕后的点击图像
正常=按钮的图像时选择
时,要做到这一点,我创建没有选择充满=按钮的图像的if/else语句:
@IBAction FUNC option1ButtonAction(发件人:AnyObject){
if (option1Button.currentImage == UIImage(named: "normal")) {
if option2Button.currentImage == UIImage(named: "filled") || option3Button.currentImage == UIImage(named: "filled") || option4Button.currentImage == UIImage(named: "filled") || option5Button.currentImage == UIImage(named: "filled") {
option1Button.setImage(filled, forState: .Normal)
option2Button.setImage(normal, forState: .Normal)
option3Button.setImage(normal, forState: .Normal)
option4Button.setImage(normal, forState: .Normal)
option5Button.setImage(normal, forState: .Normal)
}
else {
option1Button.setImage(filled, forState: .Normal)
}
}
else {
option1Button.setImage(normal, forState: .Normal)
}
} 然后我做了一个if if1Button.currentImage == UIImage(named:“filled”)语句,一切正常,但我有一个问题,当用户按下h ome按钮,然后直接进入应用程序,即使点击按钮,按钮仍然具有“正常”图像。
里面的viewDidDisappear功能我把下面的代码,希望解决这个问题:
option1Button.setImage(normal, forState: .Normal)
option2Button.setImage(normal, forState: .Normal)
option3Button.setImage(normal, forState: .Normal)
option4Button.setImage(normal, forState: .Normal)
option5Button.setImage(normal, forState: .Normal)
但我仍然有问题发生。我会很感激提供的任何帮助。