我有 3 个按钮供用户选择他们希望查看的类别。
它们定义如下:
//outlets
@IBOutlet weak var ChineseButton: UIButton!
@IBOutlet weak var IndianButton: UIButton!
@IBOutlet weak var MexicanButton: UIButton!
我对这些按钮进行了以下操作(将原始图像按钮更改为灰色版本):
//动作
@IBAction func ChineseButtonPressed(sender: UIButton)
{
ChineseButton.setImage(UIImage(named: "chinese.png"), forState: UIControlState.Normal)
ChineseButton.setImage(UIImage(named: "chinese.png"), forState: UIControlState.Selected)
IndianButton.setImage(UIImage(named: "grey-indian.png"), forState: UIControlState.Normal)
MexicanButton.setImage(UIImage(named: "grey-mexican.png"), forState: UIControlState.Normal)
}
@IBAction func EightFacedButtonPressed(sender: UIButton) {
IndianButton.setImage(UIImage(named: "indian.png"), forState: UIControlState.Normal)
IndianButton.setImage(UIImage(named: "indian.png"), forState: UIControlState.Selected)
ChineseButton.setImage(UIImage(named: "grey-chinese.png"), forState: UIControlState.Normal)
MexicanButton.setImage(UIImage(named: "grey-mexican.png"), forState: UIControlState.Normal)
}
@IBAction func TweleveFacedButtonPressed(sender: UIButton) {
MexicanButton.setImage(UIImage(named: "mexican.png"), forState: UIControlState.Normal)
MexicanButton.setImage(UIImage(named: "mexican.png"), forState: UIControlState.Selected)
ChineseButton.setImage(UIImage(named: "grey-chinese.png"), forState: UIControlState.Normal)
IndianButton.setImage(UIImage(named: "grey-indian.png"), forState: UIControlState.Normal)
}
这个动作函数还决定了 UIControlState,我有另一个按钮,一旦单击它将带你到另一个页面,但需要了解选择了哪个按钮。
我尝试了以下但它似乎无法识别选择了哪个按钮?
@IBAction func GenerateButton(sender: UIButton) {
if ChineseButton.selected == true{
println("Chinese button was selected")
}
我是 swift 新手,所以任何帮助将不胜感激!
谢谢 :)