私は(one,numOne),(two,numTwo),(three,numThree)
という名前の3組のボタンを持っています。すべてのボタンの初めはtintColor
はblack
です。ペアのボタンの色をblue
に変更したい場合は、そのペアの1つのボタンをタップし、他のペアをタップするとに戻ります。私はコードに従うことでこれを行うことができますが、以下の方法よりも短い方法がありますか?タップしたボタンのペアの色を変更するにはどうすればいいですか?
@IBOutlet weak var one: UIButton!
@IBOutlet weak var two: UIButton!
@IBOutlet weak var three: UIButton!
@IBOutlet weak var numOne: UIButton!
@IBOutlet weak var numTwo: UIButton!
@IBOutlet weak var numThree: UIButton!
@IBAction func buttonTapped(_ sender: UIButton) {
if sender == one || sender == numOne
{
one.tintColor = UIColor.blue
numOne.tintColor = UIColor.blue
two.tintColor = UIColor.black
numTwo.tintColor = UIColor.black
three.tintColor = UIColor.black
numThree.tintColor = UIColor.black
}
else if sender == two || sender == numTwo
{
two.tintColor = UIColor.blue
numTwo.tintColor = UIColor.blue
one.tintColor = UIColor.black
numOne.tintColor = UIColor.black
three.tintColor = UIColor.black
numThree.tintColor = UIColor.black
}
else
{
three.tintColor = UIColor.blue
numThree.tintColor = UIColor.blue
two.tintColor = UIColor.black
numTwo.tintColor = UIColor.black
one.tintColor = UIColor.black
numOne.tintColor = UIColor.black
}
}
それは最も簡単ですが、私はあなたが最短にしたいと思います。 :D –
はい、私は最短を意味してください。 – leaner122
numOne、numTwo、numThreeとは何ですか? –