質問編集履歴
2
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
### 概要
|
2
2
|
|
3
3
|
5ページ分する横スクロールアプリです
|
4
4
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
### 実現したいこと
|
10
10
|
|
11
11
|
・全ての端末でスクロールビューを実現したい
|
12
12
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
|
21
|
+
### 試したこと
|
22
22
|
|
23
23
|
1.ScrollViewに"Add New Constraints"で上下左右0の制約を追加
|
24
24
|
|
@@ -45,6 +45,8 @@
|
|
45
45
|
・Xcode11のIBに追加されたContentLayoutGuideとFrameLayoutGuideについて__
|
46
46
|
|
47
47
|
|
48
|
+
|
49
|
+
### コード
|
48
50
|
|
49
51
|
```
|
50
52
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,6 +48,68 @@
|
|
48
48
|
|
49
49
|
```
|
50
50
|
|
51
|
+
import UIKit
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
class ViewController: UIViewController {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
@IBOutlet weak var scrollView: UIScrollView!
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
var imageArray = ["1","2","3","4","5"]
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
override func viewDidLoad() {
|
68
|
+
|
69
|
+
super.viewDidLoad()
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
scrollView.isPagingEnabled = true
|
74
|
+
|
75
|
+
scrollView.contentSize = CGSize(width: view.frame.size.width*5, height: view.frame.size.height)
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
for i in 0...4{
|
82
|
+
|
83
|
+
print(i)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
let imageView = UIImageView()
|
88
|
+
|
89
|
+
let imageName = imageArray[i]
|
90
|
+
|
91
|
+
imageView.image = UIImage(named: "(imageName).jpg")
|
92
|
+
|
93
|
+
imageView.frame = CGRect(x: CGFloat(i)*view.frame.size.width, y: 0, width: view.frame.size.width, height: view.frame.size.height)
|
94
|
+
|
95
|
+
imageView.contentMode = .scaleAspectFit
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
scrollView.addSubview(imageView)
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
51
109
|
|
52
110
|
|
53
111
|
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
![イメージ説明](c016b9c3f53f5932565abd8603af19f0.png)
|