回答編集履歴
2
修正
test
CHANGED
@@ -59,3 +59,67 @@
|
|
59
59
|
|
60
60
|
|
61
61
|
![image](d509c91dd606425a67220226edc26bfc.png)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
もう一つの案としては`bringSubviewToFront(view: UIView)`メソッドを使用して指定したViewのTopに配置し直すというやり方です。
|
66
|
+
|
67
|
+
※全ての`view`を乗せた後に呼び出すとTopに配置されます。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```swift
|
72
|
+
|
73
|
+
import UIKit
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class ViewController: UIViewController {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
var topImageView = UIImageView()
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
override func viewDidLoad() {
|
86
|
+
|
87
|
+
super.viewDidLoad()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
topImageView.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
|
92
|
+
|
93
|
+
topImageView.image = UIImage(named: "ImageName")
|
94
|
+
|
95
|
+
topImageView.backgroundColor = UIColor.yellowColor()
|
96
|
+
|
97
|
+
view.addSubview(topImageView)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
let color: [UIColor] = [.greenColor(), .redColor(), .blueColor(), .orangeColor(), .grayColor()]
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
for i in 0..<5 {
|
106
|
+
|
107
|
+
let imageV = UIImageView()
|
108
|
+
|
109
|
+
imageV.frame = CGRect(x: 30 * i, y: 30 * i, width: 200, height: 200)
|
110
|
+
|
111
|
+
imageV.backgroundColor = color[i]
|
112
|
+
|
113
|
+
view.addSubview(imageV)
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
view.bringSubviewToFront(topImageView)
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
```
|
1
修正
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
`UIView`クラスの`insertSubview(view: UIView, belowSubview siblingSubview: UIView)`メソッドを使用するとTopImageViewの下に後で追加したViewが挿入されます。
|
2
|
+
|
3
|
+
※ 固定されるのでは無くその下に挿入されていく感じですね。
|
2
4
|
|
3
5
|
|
4
6
|
|