色々方法はあると思いますが
enum で状態持たせるのが良いと思います。
通常は文字列だけでなくタップ時の処理も変わるはずですので。
swift
1class ViewController: UIViewController {
2 enum ButtonNameType {
3 case start
4 case rest
5 case back
6 }
7 var buttonNameType: ButtonNameType!
8
9 override func viewDidLoad() {
10 super.viewDidLoad()
11 self.buttonNameType = .start
12 self.button.setTitle("開始", for: .normal)
13 }
14
15 // 略
16
17 @IBAction func buttonAction(_ sender: UIButton) {
18 switch self.buttonNameType {
19 case .start:
20 self.buttonNameType = .rest
21 self.button.setTitle("休憩", for: .normal)
22 // 開始ボタンタップ時に他に処理したい際にここに記載
23 case .rest:
24 self.buttonNameType = .back
25 self.button.setTitle("戻り", for: .normal)
26 // 休憩ボタンタップ時に他に処理したい際にここに記載
27 case .back:
28 self.buttonNameType = .start
29 self.button.setTitle("開始", for: .normal
30 // 戻りボタンタップ時に他に処理したい際にここに記載
31 }
32 }
33}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 07:28
2019/08/05 16:04
2019/08/05 17:13