回答編集履歴
2
修正
answer
CHANGED
@@ -28,4 +28,36 @@
|
|
28
28
|
|
29
29
|
実行すると黄色い`TopImageView`の下に追加されています。
|
30
30
|
|
31
|
-

|
31
|
+

|
32
|
+
|
33
|
+
もう一つの案としては`bringSubviewToFront(view: UIView)`メソッドを使用して指定したViewのTopに配置し直すというやり方です。
|
34
|
+
※全ての`view`を乗せた後に呼び出すとTopに配置されます。
|
35
|
+
|
36
|
+
```swift
|
37
|
+
import UIKit
|
38
|
+
|
39
|
+
class ViewController: UIViewController {
|
40
|
+
|
41
|
+
var topImageView = UIImageView()
|
42
|
+
|
43
|
+
override func viewDidLoad() {
|
44
|
+
super.viewDidLoad()
|
45
|
+
|
46
|
+
topImageView.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
|
47
|
+
topImageView.image = UIImage(named: "ImageName")
|
48
|
+
topImageView.backgroundColor = UIColor.yellowColor()
|
49
|
+
view.addSubview(topImageView)
|
50
|
+
|
51
|
+
let color: [UIColor] = [.greenColor(), .redColor(), .blueColor(), .orangeColor(), .grayColor()]
|
52
|
+
|
53
|
+
for i in 0..<5 {
|
54
|
+
let imageV = UIImageView()
|
55
|
+
imageV.frame = CGRect(x: 30 * i, y: 30 * i, width: 200, height: 200)
|
56
|
+
imageV.backgroundColor = color[i]
|
57
|
+
view.addSubview(imageV)
|
58
|
+
}
|
59
|
+
|
60
|
+
view.bringSubviewToFront(topImageView)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
```
|
1
修正
answer
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
`UIView`クラスの`insertSubview(view: UIView, belowSubview siblingSubview: UIView)`メソッドを使用するとTopImageViewの下に後で追加したViewが挿入されます。
|
2
|
+
※ 固定されるのでは無くその下に挿入されていく感じですね。
|
2
3
|
|
3
4
|
```swift
|
4
5
|
class ViewController: UIViewController {
|