回答編集履歴

4

修正

2016/06/03 14:45

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -57,3 +57,367 @@
57
57
  よくよく見ると今回の回答は
58
58
 
59
59
  前回の質問([Thread 1 : breakpoint 1.1](https://teratail.com/questions/36807))のTakeOneさんの回答1と2ですね。
60
+
61
+
62
+
63
+
64
+
65
+ 回答追記
66
+
67
+ ---
68
+
69
+ ```swift
70
+
71
+ import UIKit
72
+
73
+
74
+
75
+ class ViewController: UIViewController {
76
+
77
+
78
+
79
+ let labelresult = UILabel() //計算結果を表示させる
80
+
81
+
82
+
83
+ override func viewDidLoad() {
84
+
85
+ super.viewDidLoad()
86
+
87
+ // Do any additional setup after loading the view, typically from a nib.
88
+
89
+ self.Calculation()
90
+
91
+ }
92
+
93
+
94
+
95
+ func Calculation() {
96
+
97
+
98
+
99
+ let backView = UIView() //背景
100
+
101
+ backView.frame = CGRect(x:0.8, y:20.0, width:373.0, height:646.0)
102
+
103
+ backView.backgroundColor = UIColor.whiteColor()
104
+
105
+ self.view.addSubview(backView)
106
+
107
+
108
+
109
+ let label0 = UIButton() //1
110
+
111
+ label0.frame = CGRectMake(230, 10, 40, 40)
112
+
113
+ label0.backgroundColor = UIColor.blackColor()
114
+
115
+ label0.setTitle("0", forState: .Normal)
116
+
117
+ label0.setTitleColor(UIColor.cyanColor(), forState: UIControlState .Normal)
118
+
119
+ label0.titleLabel!.font = UIFont.systemFontOfSize(29)
120
+
121
+ label0.addTarget(self, action: #selector(ViewController.num(_:)), forControlEvents: UIControlEvents .TouchDown)
122
+
123
+ label0.tag = 0
124
+
125
+ backView.addSubview(label0)
126
+
127
+
128
+
129
+ let label1 = UIButton() //1
130
+
131
+ label1.frame = CGRectMake(1, 272, 124, 124)
132
+
133
+ label1.backgroundColor = UIColor.redColor()
134
+
135
+ label1.setTitle("1", forState: .Normal)
136
+
137
+ label1.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
138
+
139
+ label1.titleLabel!.font = UIFont.systemFontOfSize(29)
140
+
141
+ label1.tag = 1
142
+
143
+ backView.addSubview(label1)
144
+
145
+
146
+
147
+ let label2 = UIButton() //2
148
+
149
+ label2.frame = CGRectMake(126, 272, 124, 124)
150
+
151
+ label2.backgroundColor = UIColor.redColor()
152
+
153
+ label2.setTitle("2", forState: .Normal)
154
+
155
+ label2.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
156
+
157
+ label2.titleLabel!.font = UIFont.systemFontOfSize(29)
158
+
159
+ label2.tag = 2
160
+
161
+ backView.addSubview(label2)
162
+
163
+
164
+
165
+ let label3 = UIButton() //3
166
+
167
+ label3.frame = CGRectMake(251,272, 124, 124)
168
+
169
+ label3.backgroundColor = UIColor.redColor()
170
+
171
+ label3.setTitle("3", forState: .Normal)
172
+
173
+ label3.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
174
+
175
+ label3.titleLabel!.font = UIFont.systemFontOfSize(29)
176
+
177
+ label3.tag = 3
178
+
179
+ backView.addSubview(label3)
180
+
181
+
182
+
183
+ let label4 = UIButton() //4
184
+
185
+ label4.frame = CGRectMake( 1, 397, 124, 124)
186
+
187
+ label4.backgroundColor = UIColor.blackColor()
188
+
189
+ label4.setTitle("4", forState: .Normal)
190
+
191
+ label4.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
192
+
193
+ label4.titleLabel!.font = UIFont.systemFontOfSize(29)
194
+
195
+ label4.tag = 4
196
+
197
+ backView.addSubview(label4)
198
+
199
+
200
+
201
+ let label5 = UIButton() //5
202
+
203
+ label5.frame = CGRectMake(126,397, 124, 124)
204
+
205
+ label5.backgroundColor = UIColor.blackColor()
206
+
207
+ label5.setTitle("5", forState: .Normal)
208
+
209
+ label5.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
210
+
211
+ label5.titleLabel!.font = UIFont.systemFontOfSize(29)
212
+
213
+ label5.tag = 5
214
+
215
+ backView.addSubview(label5)
216
+
217
+
218
+
219
+ let label6 = UIButton() //6
220
+
221
+ label6.frame = CGRectMake(251, 397, 124, 124)
222
+
223
+ label6.backgroundColor = UIColor.blackColor()
224
+
225
+ label6.setTitle("6", forState: .Normal)
226
+
227
+ label6.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
228
+
229
+ label6.titleLabel!.font = UIFont.systemFontOfSize(29)
230
+
231
+ label6.tag = 6
232
+
233
+ backView.addSubview(label6)
234
+
235
+
236
+
237
+ let label7 = UIButton() //7
238
+
239
+ label7.frame = CGRectMake(1, 522, 124, 124)
240
+
241
+ label7.backgroundColor = UIColor.blueColor()
242
+
243
+ label7.setTitle("7", forState: .Normal)
244
+
245
+ label7.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
246
+
247
+ label7.titleLabel!.font = UIFont.systemFontOfSize(29)
248
+
249
+ label7.tag = 7
250
+
251
+ backView.addSubview(label7)
252
+
253
+
254
+
255
+ let label8 = UIButton() //8
256
+
257
+ label8.frame = CGRectMake(126, 522, 124, 124)
258
+
259
+ label8.backgroundColor = UIColor.blueColor()
260
+
261
+ label8.setTitle("8", forState: .Normal)
262
+
263
+ label8.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
264
+
265
+ label8.titleLabel!.font = UIFont.systemFontOfSize(29)
266
+
267
+ label6.tag = 8
268
+
269
+ backView.addSubview(label8)
270
+
271
+
272
+
273
+ let label9 = UIButton() //9
274
+
275
+ label9.frame = CGRectMake(251, 522, 124, 124)
276
+
277
+ label9.backgroundColor = UIColor.blueColor()
278
+
279
+ label9.setTitle("9", forState: .Normal)
280
+
281
+ label9.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
282
+
283
+ label9.titleLabel!.font = UIFont.systemFontOfSize(29)
284
+
285
+ label6.tag = 9
286
+
287
+ backView.addSubview(label9)
288
+
289
+
290
+
291
+ //足し算
292
+
293
+ let labelplus = UIButton()
294
+
295
+ labelplus.frame = CGRect(x: 10, y: 10, width: 40, height: 40)
296
+
297
+ labelplus.backgroundColor = UIColor.blackColor()
298
+
299
+ labelplus.setTitle("+", forState: .Normal)
300
+
301
+ labelplus.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
302
+
303
+ labelplus.titleLabel!.font = UIFont.systemFontOfSize(29)
304
+
305
+ labelplus.tag = 01
306
+
307
+ backView.addSubview(labelplus)
308
+
309
+
310
+
311
+ let labelminus = UIButton() //引き算
312
+
313
+ labelminus.frame = CGRect(x: 60, y: 10, width: 40, height: 40)
314
+
315
+ labelminus.backgroundColor = UIColor.blackColor()
316
+
317
+ labelminus.setTitle("-", forState: .Normal)
318
+
319
+ labelminus.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
320
+
321
+ labelminus.titleLabel!.font = UIFont.systemFontOfSize(29)
322
+
323
+ labelminus.tag = 02
324
+
325
+ backView.addSubview(labelminus)
326
+
327
+
328
+
329
+ let labelproduct = UIButton() //掛け算
330
+
331
+ labelproduct.frame = CGRect(x: 110, y: 10, width: 40, height: 40)
332
+
333
+ labelproduct.backgroundColor = UIColor.blackColor()
334
+
335
+ labelproduct.setTitle("x", forState: .Normal)
336
+
337
+ labelproduct.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
338
+
339
+ labelproduct.titleLabel!.font = UIFont.systemFontOfSize(29)
340
+
341
+ labelproduct.tag = 03
342
+
343
+ backView.addSubview(labelproduct)
344
+
345
+
346
+
347
+ let labelquontient = UIButton() //割り算
348
+
349
+ labelquontient.frame = CGRect(x: 180, y: 10, width: 40, height: 40)
350
+
351
+ labelquontient.backgroundColor = UIColor.blackColor()
352
+
353
+ labelquontient.setTitle("/", forState: .Normal)
354
+
355
+ labelquontient.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
356
+
357
+ labelquontient.titleLabel!.font = UIFont.systemFontOfSize(29)
358
+
359
+ labelquontient.tag = 04
360
+
361
+ backView.addSubview(labelquontient)
362
+
363
+
364
+
365
+ let labelclear = UIButton() //現在の計算結果を0にリセット
366
+
367
+ labelclear.frame = CGRect(x: 280, y: 10, width: 40, height: 40)
368
+
369
+ labelclear.backgroundColor = UIColor.blackColor()
370
+
371
+ labelclear.setTitle("C", forState: .Normal)
372
+
373
+ labelclear.setTitleColor(UIColor.cyanColor(), forState: UIControlState.Normal)
374
+
375
+ labelclear.titleLabel!.font = UIFont.systemFontOfSize(29)
376
+
377
+ labelclear.tag = 05
378
+
379
+ backView.addSubview(labelclear)
380
+
381
+
382
+
383
+
384
+
385
+ labelresult.frame = CGRect(x: 1, y: 60, width: 370, height: 210)
386
+
387
+ labelresult.backgroundColor = UIColor.lightGrayColor()
388
+
389
+ backView.addSubview(labelresult)
390
+
391
+ }
392
+
393
+
394
+
395
+ func num(sender:UIButton){
396
+
397
+ switch sender.tag {
398
+
399
+ case 0:
400
+
401
+ labelresult.text = "0"
402
+
403
+ default: break
404
+
405
+ }
406
+
407
+ }
408
+
409
+
410
+
411
+ override func didReceiveMemoryWarning() {
412
+
413
+ super.didReceiveMemoryWarning()
414
+
415
+ // Dispose of any resources that can be recreated.
416
+
417
+ }
418
+
419
+
420
+
421
+ }
422
+
423
+ ```

3

修正

2016/06/03 14:45

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -53,3 +53,7 @@
53
53
  }
54
54
 
55
55
  ```
56
+
57
+ よくよく見ると今回の回答は
58
+
59
+ 前回の質問([Thread 1 : breakpoint 1.1](https://teratail.com/questions/36807))のTakeOneさんの回答1と2ですね。

2

修正

2016/06/03 13:24

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,4 +1,4 @@
1
- 以下の2点を修正することで0が表示されると思います。
1
+ 以下の2点を修正することで""が表示されます。
2
2
 
3
3
 
4
4
 

1

修正

2016/06/03 13:12

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -36,6 +36,8 @@
36
36
 
37
37
  // 上記を修正するとlabelresultが定義されていないとエラーになりますので、以下の様にlabelresultをインスタンス変数で定義します。
38
38
 
39
+ // ※ Calculation()の中にある let labelresult = UILabel()は消してください。
40
+
39
41
  // 変更②
40
42
 
41
43
  import UIKit