質問編集履歴
1
貼り付けたコードが一部のみだったので、全体を貼り付けました。しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,7 +14,33 @@
|
|
14
14
|
### 該当のソースコード
|
15
15
|
|
16
16
|
```swift
|
17
|
+
|
18
|
+
import UIKit
|
19
|
+
|
20
|
+
class FaceItemViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate{
|
21
|
+
|
22
|
+
private let faces = ["face0", "face1", "face2", "face3", "face4", "face5","face6", "face7", "face8", "face9", "face10", "face11","face12", "face13", "face14"]
|
23
|
+
|
24
|
+
@IBOutlet weak var collectionView: UICollectionView!
|
25
|
+
|
26
|
+
override func viewDidLoad() {
|
27
|
+
super.viewDidLoad()
|
28
|
+
|
29
|
+
// レイアウトを調整
|
30
|
+
let layout = UICollectionViewFlowLayout()
|
31
|
+
layout.sectionInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
|
32
|
+
collectionView.collectionViewLayout = layout
|
33
|
+
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
//セルの表示数
|
39
|
+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
40
|
+
return faces.count;
|
41
|
+
}
|
42
|
+
|
17
|
-
// セル(要素)に表示する内容
|
43
|
+
// セル(要素)に表示する内容
|
18
44
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
19
45
|
|
20
46
|
let cell : UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier:"FaceCell",for: indexPath )
|
@@ -31,6 +57,19 @@
|
|
31
57
|
return cell
|
32
58
|
|
33
59
|
}
|
60
|
+
|
61
|
+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
62
|
+
let horizontalSpace : CGFloat = 20
|
63
|
+
let cellSize : CGFloat = self.view.bounds.width / 3 - horizontalSpace
|
64
|
+
return CGSize(width: cellSize, height: cellSize)
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
34
73
|
```
|
35
74
|
|
36
75
|
### 試したこと
|