質問編集履歴

1

貼り付けたコードが一部のみだったので、全体を貼り付けました。しました。

2020/01/15 10:49

投稿

YokoGuddy
YokoGuddy

スコア5

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,59 @@
30
30
 
31
31
  ```swift
32
32
 
33
+
34
+
35
+ import UIKit
36
+
37
+
38
+
39
+ class FaceItemViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate{
40
+
41
+
42
+
43
+ private let faces = ["face0", "face1", "face2", "face3", "face4", "face5","face6", "face7", "face8", "face9", "face10", "face11","face12", "face13", "face14"]
44
+
45
+
46
+
47
+ @IBOutlet weak var collectionView: UICollectionView!
48
+
49
+
50
+
51
+ override func viewDidLoad() {
52
+
53
+ super.viewDidLoad()
54
+
55
+
56
+
57
+ // レイアウトを調整
58
+
59
+ let layout = UICollectionViewFlowLayout()
60
+
61
+ layout.sectionInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
62
+
63
+ collectionView.collectionViewLayout = layout
64
+
65
+
66
+
67
+
68
+
69
+ }
70
+
71
+
72
+
73
+
74
+
75
+ //セルの表示数
76
+
77
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
78
+
79
+ return faces.count;
80
+
81
+ }
82
+
83
+
84
+
33
- // セル(要素)に表示する内容
85
+ // セル(要素)に表示する内容
34
86
 
35
87
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
36
88
 
@@ -64,6 +116,32 @@
64
116
 
65
117
  }
66
118
 
119
+
120
+
121
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
122
+
123
+ let horizontalSpace : CGFloat = 20
124
+
125
+ let cellSize : CGFloat = self.view.bounds.width / 3 - horizontalSpace
126
+
127
+ return CGSize(width: cellSize, height: cellSize)
128
+
129
+ }
130
+
131
+
132
+
133
+
134
+
135
+ }
136
+
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+
144
+
67
145
  ```
68
146
 
69
147