回答編集履歴
1
s
test
CHANGED
@@ -37,3 +37,57 @@
|
|
37
37
|
@IBOutlet weak var subbutton: CustomButton!
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
`UIButton`に対して背景を赤くするメソッドを作りそれを呼ぶ方法
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```swift
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
import UIKit
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
class ViewController: UIViewController {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
@IBOutlet weak var button: UIButton!
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
override func viewDidLoad() {
|
64
|
+
|
65
|
+
super.viewDidLoad()
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
button.backgroundRedColor()
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
extension UIButton {
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// 背景色を赤にするメソッド
|
84
|
+
|
85
|
+
func backgroundRedColor() {
|
86
|
+
|
87
|
+
backgroundColor = .red
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|