ボタン12345を用意いしました。ボタン5は非表示にしています。
なぜ非表示かというと、ボタン1234のうち1、2をタップ したとき、1、3をタップした時1、4を、2、3を......というように二つのボタンをタップした時(バックグラウンドの色が青になった時)にボタン5を表示させたいからです。
まずボタン5を非表示にする場合
button5.isHidden = true
のコードの場所はここでいいのでしょうか?
あと、私が実行したいことの解釈はbutton1,2のバックグラウンドカラーが青になった時button5を表示。でいいんでしょうか?
だとしても各ボタンのActionの続きに?
outletの所に?と基礎的なことがわかっていないため、悩みに悩んでいます。
解答よろしくお願いします!
import UIKit class kamotsuViewController: UIViewController { @IBOutlet weak var button1: UIButton! @IBOutlet weak var button2: UIButton! @IBOutlet weak var button3: UIButton! @IBOutlet weak var button4: UIButton! @IBOutlet weak var button5: UIButton! override func viewDidLoad() { super.viewDidLoad() button5.isHidden = true } @IBAction func button1(_ sender: UIButton) { if button1.backgroundColor == nil{ button1.backgroundColor = UIColor.blue } else if button1.backgroundColor == UIColor.blue{ button1.backgroundColor = nil } } @IBAction func button2(_ sender: UIButton) { if button2.backgroundColor == nil{ button2.backgroundColor = UIColor.blue } else if button2.backgroundColor == UIColor.blue{ button2.backgroundColor = nil } } @IBAction func button3(_ sender: UIButton) { if button3.backgroundColor == nil{ button3.backgroundColor = UIColor.blue } else if button3.backgroundColor == UIColor.blue{ button3.backgroundColor = nil } } @IBAction func button4(_ sender: UIButton) { if button4.backgroundColor == nil{ button4.backgroundColor = UIColor.blue } else if button4.backgroundColor == UIColor.blue{ button4.backgroundColor = nil } }
回答2件
あなたの回答
tips
プレビュー