teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

修正

2018/12/03 06:58

投稿

MasakiHori
MasakiHori

スコア3391

answer CHANGED
@@ -46,7 +46,8 @@
46
46
  func toggle() {
47
47
 
48
48
  statedText.toggle()
49
- button.text = statedText.text
49
+ // button.text = statedText.text
50
+ button.setTitle(statedText.text,for: UIControlState.normal)
50
51
  }
51
52
 
52
53
  init(button: UIButton, onText: String, offText: String) {

4

label -> Button

2018/12/03 06:58

投稿

MasakiHori
MasakiHori

スコア3391

answer CHANGED
@@ -75,7 +75,7 @@
75
75
  ...
76
76
  ...
77
77
 
78
- return StatedLabel(label: label, onText: "オンの時のテキスト", offText: "オフの時のテキスト")
78
+ return StatedButton(button: button, onText: "オンの時のテキスト", offText: "オフの時のテキスト")
79
79
  }
80
80
 
81
81
  ...

3

label -> Button

2018/11/29 06:52

投稿

MasakiHori
MasakiHori

スコア3391

answer CHANGED
@@ -89,7 +89,7 @@
89
89
  @objc func buttonTapped(_ sender: UIButton) {
90
90
 
91
91
  buttons
92
- .filter { statedButton in sender == statedButton.label }
92
+ .filter { statedButton in sender == statedButton.button }
93
93
  .first
94
94
  .map { statedButton in statedButton.toggle() }
95
95
  }

2

label -> Button

2018/11/29 06:47

投稿

MasakiHori
MasakiHori

スコア3391

answer CHANGED
@@ -86,7 +86,7 @@
86
86
  ...
87
87
  ...
88
88
 
89
- @objc func buttonTapped(_ sender: UILabel) {
89
+ @objc func buttonTapped(_ sender: UIButton) {
90
90
 
91
91
  buttons
92
92
  .filter { statedButton in sender == statedButton.label }

1

label -> Button

2018/11/29 06:46

投稿

MasakiHori
MasakiHori

スコア3391

answer CHANGED
@@ -39,19 +39,19 @@
39
39
  }
40
40
  }
41
41
 
42
- class StatedLabel {
42
+ class StatedButton {
43
43
  private var statedText: StatedText
44
- let label: UILabel
44
+ let button: UIButton
45
45
 
46
46
  func toggle() {
47
47
 
48
48
  statedText.toggle()
49
- label.text = statedText.text
49
+ button.text = statedText.text
50
50
  }
51
51
 
52
- init(label: UILabel, onText: String, offText: String) {
52
+ init(button: UIButton, onText: String, offText: String) {
53
53
 
54
- self.label = label
54
+ self.button= button
55
55
  self.statedText = StatedText(onText: onText, offText: offText)
56
56
  }
57
57
  }
@@ -61,7 +61,7 @@
61
61
  class ViewController: UIViewController , UIScrollViewDelegate , UITextFieldDelegate {
62
62
  ...
63
63
  ...
64
- var labels: [StatedLabel] = []
64
+ var buttons: [StatedButton] = []
65
65
 
66
66
  ....
67
67
  ....
@@ -70,8 +70,8 @@
70
70
  override func viewDidLoad() {
71
71
  ...
72
72
  ...
73
- labels = sam1.sam1.map { sample in
73
+ buttons = sam1.sam1.map { sample in
74
- let label = UILabbel()
74
+ let button = UIButton()
75
75
  ...
76
76
  ...
77
77
 
@@ -88,10 +88,10 @@
88
88
 
89
89
  @objc func buttonTapped(_ sender: UILabel) {
90
90
 
91
- labels
91
+ buttons
92
- .filter { statedLabel in sender == statedLabel.label }
92
+ .filter { statedButton in sender == statedButton.label }
93
93
  .first
94
- .map { statedLabel in statedLabel.toggle() }
94
+ .map { statedButton in statedButton.toggle() }
95
95
  }
96
96
 
97
97
  ...