// SomeViewController.swift
class SomeViewController: UIViewController {
lazy var horizontalCollection = UICollectionView(
frame: .zero,
collectionViewLayout: configureCollectionLayout()
)
..
override func viewDidLoad() {
super.viewDidLoad()
view.addSubView(horizontalCollection)
horizontalCollection.snp.makeConstraints { make in
make.horizontalEdges.top.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(300)
}
}
func configureCollectionLayout() -> UICollectionViewLayout {
let layout = UICollectionViewFlowLayout()
let width = UIScreen.main.bounds.width * 0.6
let height = UIScreen.main.bounds.height / 3
layout.itemSize = CGSize(width: width, height: height)
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 20
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
return layout
}
}