回答編集履歴
3
追記
test
CHANGED
@@ -11,6 +11,10 @@
|
|
11
11
|
class ViewController: UIViewController {
|
12
12
|
|
13
13
|
|
14
|
+
|
15
|
+
let buttoArray: [UIButton] = []
|
16
|
+
|
17
|
+
|
14
18
|
|
15
19
|
override func viewDidLoad() {
|
16
20
|
|
@@ -50,8 +54,6 @@
|
|
50
54
|
|
51
55
|
|
52
56
|
|
53
|
-
|
54
|
-
|
55
57
|
// Button3を作成
|
56
58
|
|
57
59
|
let button3 = UIButton(type: .Custom)
|
@@ -68,11 +70,9 @@
|
|
68
70
|
|
69
71
|
|
70
72
|
|
71
|
-
|
72
|
-
|
73
73
|
// UIButtonの配列
|
74
74
|
|
75
|
-
|
75
|
+
buttoArray = [button1, button2, button3]
|
76
76
|
|
77
77
|
|
78
78
|
|
@@ -128,15 +128,13 @@
|
|
128
128
|
|
129
129
|
|
130
130
|
|
131
|
+
let buttoArray: [UIButton] = []
|
132
|
+
|
133
|
+
|
134
|
+
|
131
135
|
override func viewDidLoad() {
|
132
136
|
|
133
137
|
super.viewDidLoad()
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// UIButtonの配列
|
138
|
-
|
139
|
-
var buttoArray: [UIButton] = []
|
140
138
|
|
141
139
|
|
142
140
|
|
@@ -146,11 +144,7 @@
|
|
146
144
|
|
147
145
|
|
148
146
|
|
149
|
-
|
150
|
-
|
151
147
|
for index in 0 ..< buttonCount {
|
152
|
-
|
153
|
-
|
154
148
|
|
155
149
|
// Buttonを作成
|
156
150
|
|
@@ -169,8 +163,6 @@
|
|
169
163
|
buttoArray.append(button)
|
170
164
|
|
171
165
|
}
|
172
|
-
|
173
|
-
|
174
166
|
|
175
167
|
|
176
168
|
|
2
追記
test
CHANGED
@@ -107,3 +107,97 @@
|
|
107
107
|
実行結果
|
108
108
|
|
109
109
|
![image](612f0212b0c5ac3dfa18a5f352d1daab.png)
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
量産型
|
116
|
+
|
117
|
+
---
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```swift
|
122
|
+
|
123
|
+
import UIKit
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
class ViewController: UIViewController {
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
override func viewDidLoad() {
|
132
|
+
|
133
|
+
super.viewDidLoad()
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
// UIButtonの配列
|
138
|
+
|
139
|
+
var buttoArray: [UIButton] = []
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
// 作成するボタンの数
|
144
|
+
|
145
|
+
let buttonCount = 5
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
for index in 0 ..< buttonCount {
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// Buttonを作成
|
156
|
+
|
157
|
+
let button = UIButton(type: .Custom)
|
158
|
+
|
159
|
+
button.frame = CGRectMake(100, 100 * CGFloat(index) + 50, 200, 50)
|
160
|
+
|
161
|
+
button.setTitle("button", forState: .Normal)
|
162
|
+
|
163
|
+
button.setTitleColor(UIColor.whiteColor(), forState: .Normal)
|
164
|
+
|
165
|
+
button.backgroundColor = UIColor.blueColor()
|
166
|
+
|
167
|
+
button.tag = index
|
168
|
+
|
169
|
+
buttoArray.append(button)
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
// 配列から取り出してViewに追加
|
178
|
+
|
179
|
+
for button in buttoArray {
|
180
|
+
|
181
|
+
view.addSubview(button)
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
override func didReceiveMemoryWarning() {
|
190
|
+
|
191
|
+
super.didReceiveMemoryWarning()
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
![aaa](1cd99ae1e11229d14e1bbc0741af1e71.png)
|
1
修正
test
CHANGED
@@ -104,6 +104,6 @@
|
|
104
104
|
|
105
105
|
|
106
106
|
|
107
|
-
|
107
|
+
実行結果
|
108
108
|
|
109
109
|
![image](612f0212b0c5ac3dfa18a5f352d1daab.png)
|