質問編集履歴
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,23 +10,35 @@
|
|
10
10
|
|
11
11
|
```
|
12
12
|
|
13
|
+
import UIKit
|
14
|
+
|
15
|
+
|
16
|
+
|
13
|
-
class CustomView: UIView {
|
17
|
+
class CustomView: UIView {
|
18
|
+
|
19
|
+
|
14
20
|
|
15
21
|
override init(frame: CGRect) {
|
16
22
|
|
17
23
|
super.init(frame: frame)
|
18
24
|
|
19
|
-
bu
|
25
|
+
backgroundColor = UIColor.whiteColor()
|
20
26
|
|
27
|
+
let button = UIButton()
|
28
|
+
|
21
|
-
button.frame.size = CGSize(width:
|
29
|
+
button.frame.size = CGSize(width: 100, height: 100)
|
22
30
|
|
23
31
|
button.frame.origin = CGPoint(x: 100, y: 100)
|
24
32
|
|
33
|
+
button.backgroundColor = UIColor.blueColor()
|
34
|
+
|
35
|
+
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
36
|
+
|
25
|
-
self.addSub
|
37
|
+
self.addSubview(button)
|
26
38
|
|
27
39
|
}
|
28
40
|
|
29
|
-
|
41
|
+
|
30
42
|
|
31
43
|
required init?(coder aDecoder: NSCoder) {
|
32
44
|
|
2
コードの書き換え
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,23 +8,39 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
```
|
12
|
+
|
11
13
|
class CustomView: UIView {
|
12
|
-
|
13
|
-
@IBOutlet weak button: UIButton!
|
14
|
-
|
15
|
-
|
16
14
|
|
17
15
|
override init(frame: CGRect) {
|
18
16
|
|
19
17
|
super.init(frame: frame)
|
20
18
|
|
21
|
-
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
19
|
+
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
20
|
+
|
21
|
+
button.frame.size = CGSize(width: 61, height: 61)
|
22
|
+
|
23
|
+
button.frame.origin = CGPoint(x: 100, y: 100)
|
24
|
+
|
25
|
+
self.addSubView(button)
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
required init?(coder aDecoder: NSCoder) {
|
32
|
+
|
33
|
+
fatalError("init(coder:) has not been implemented")
|
22
34
|
|
23
35
|
}
|
24
36
|
|
25
37
|
}
|
26
38
|
|
39
|
+
```
|
27
40
|
|
41
|
+
|
42
|
+
|
43
|
+
```
|
28
44
|
|
29
45
|
class ViewController: UIViewController {
|
30
46
|
|
@@ -42,11 +58,13 @@
|
|
42
58
|
|
43
59
|
func tapButton() {
|
44
60
|
|
45
|
-
print("call")
|
61
|
+
print("call")
|
62
|
+
|
63
|
+
}
|
46
64
|
|
47
65
|
}
|
48
66
|
|
49
|
-
|
67
|
+
```
|
50
68
|
|
51
69
|
|
52
70
|
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,19 +8,41 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
class
|
11
|
+
class CustomView: UIView {
|
12
|
+
|
13
|
+
@IBOutlet weak button: UIButton!
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
override init(frame: CGRect) {
|
18
|
+
|
19
|
+
super.init(frame: frame)
|
12
20
|
|
13
21
|
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
22
|
+
|
23
|
+
}
|
14
24
|
|
15
25
|
}
|
16
26
|
|
17
27
|
|
18
28
|
|
19
|
-
cla
|
29
|
+
class ViewController: UIViewController {
|
20
30
|
|
21
|
-
func
|
31
|
+
override func loadView() {
|
32
|
+
|
33
|
+
super.loadView()
|
34
|
+
|
35
|
+
let customView = CustomView(frame: view.frame)
|
36
|
+
|
37
|
+
self.view = customView
|
38
|
+
|
39
|
+
}
|
22
40
|
|
23
41
|
|
42
|
+
|
43
|
+
func tapButton() {
|
44
|
+
|
45
|
+
print("call")
|
24
46
|
|
25
47
|
}
|
26
48
|
|