【发布时间】:2015-12-01 19:26:18
【问题描述】:
我有 5 个不同的按钮,我希望用户能够在其中选择一个(如果未选中),如果已选中则取消选择,同时取消选择另一个按钮(如果已选中) .
正常 = 未选中时的按钮图像 填充 = 选中时的按钮图像
为此,我创建了一个 if/else 语句:
@IBAction func option1ButtonAction(sender: 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 option1Button.currentImage == UIImage(named: "filled") 语句。一切都按照我想要的方式工作,但是我有一个问题。每当用户按下主页按钮然后直接返回应用程序,按钮仍然具有“正常”图像,即使单击时也是如此。
在 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)
但我仍然遇到问题。如果提供任何帮助,我将不胜感激。
【问题讨论】:
标签: ios image swift button xcode6