回答編集履歴
3
訂正
test
CHANGED
@@ -112,7 +112,11 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
115
|
-
[サンプル](https://github.com/tyobigoro/tScrollView)
|
119
|
+
[ラベルだけのサンプルあげときます。ご自身でimageViewを追加してください](https://github.com/tyobigoro/tScrollView)
|
116
120
|
|
117
121
|
|
118
122
|
|
2
追記
test
CHANGED
@@ -103,3 +103,87 @@
|
|
103
103
|
}
|
104
104
|
|
105
105
|
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
追記
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
[サンプル](https://github.com/tyobigoro/tScrollView)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
```swift
|
120
|
+
|
121
|
+
import UIKit
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class ViewController: UIViewController {
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
let scrollView = UIScrollView()
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
var strs = ["A", "B", "C", "D", "E"]
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
override func viewDidLoad() {
|
138
|
+
|
139
|
+
super.viewDidLoad()
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
scrollView.frame = self.view.frame
|
144
|
+
|
145
|
+
scrollView.backgroundColor = UIColor.red
|
146
|
+
|
147
|
+
scrollView.contentSize = CGSize(width: self.view.bounds.width * CGFloat(strs.count) , height: self.view.bounds.height)
|
148
|
+
|
149
|
+
self.view.addSubview(scrollView)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
//ページングを有効にする
|
154
|
+
|
155
|
+
scrollView.isPagingEnabled = true
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
for i in strs.enumerated() {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
let label = UILabel(frame: CGRect(x: CGFloat(i.offset)*view.bounds.size.width,
|
164
|
+
|
165
|
+
y: 0,
|
166
|
+
|
167
|
+
width: view.bounds.size.width,
|
168
|
+
|
169
|
+
height: view.bounds.size.height))
|
170
|
+
|
171
|
+
label.textAlignment = .center
|
172
|
+
|
173
|
+
label.backgroundColor = .blue
|
174
|
+
|
175
|
+
label.text = i.element
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
scrollView.addSubview(label)
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
```
|
1
訂正
test
CHANGED
@@ -36,15 +36,15 @@
|
|
36
36
|
|
37
37
|
```swift
|
38
38
|
|
39
|
-
for i in imageArray{
|
39
|
+
for i in imageArray.enumrated(){
|
40
40
|
|
41
41
|
let imageView = UIImageView()
|
42
42
|
|
43
|
-
imageView.image = UIImage(named: i)
|
43
|
+
imageView.image = UIImage(named: i.element)
|
44
44
|
|
45
45
|
imageView.frame
|
46
46
|
|
47
|
-
= CGRect(x: CGFloat(i)*view.frame.size.width,
|
47
|
+
= CGRect(x: CGFloat(i.offset + 1)*view.frame.size.width,
|
48
48
|
|
49
49
|
y: 0,
|
50
50
|
|
@@ -67,3 +67,39 @@
|
|
67
67
|
|
68
68
|
|
69
69
|
scrollViewの部分はわかりません。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
---
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
訂正
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```swift
|
84
|
+
|
85
|
+
for i in imageArray.enumerated(){
|
86
|
+
|
87
|
+
let imageView = UIImageView()
|
88
|
+
|
89
|
+
imageView.image = UIImage(named: i.element)
|
90
|
+
|
91
|
+
imageView.frame
|
92
|
+
|
93
|
+
= CGRect(x: CGFloat(i.offset + 1)*view.frame.size.width,
|
94
|
+
|
95
|
+
y: 0,
|
96
|
+
|
97
|
+
width: view.frame.size.width,
|
98
|
+
|
99
|
+
height: view.frame.size.height)
|
100
|
+
|
101
|
+
imageView.contentMode = .scaleAspectFit
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
```
|