0
我看過很多方法在UICollectionView中獲得傳送帶/一行/一節。但非工作可能,你有辦法。UICollectionViewFlowLayout一行/橫向部分
我有以下幾點:
@IBAction func openCollectionView(_ sender: Any) {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.itemSize = CGSize(width: 50, height: self.view.frame.height)
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView!.delegate = self
collectionView!.dataSource = self
collectionView!.register(PDCollectionViewCell.self, forCellWithReuseIdentifier: "cellIdentifier")
collectionView?.contentOffset.x = 20
collectionView?.reloadData()
collectionView?.layoutIfNeeded()
collectionView!.addBlurEffect()
self.view.addSubview(collectionView!)
}
這是很容易,你只需要將collectionView的佈局設置爲水平,然後在你的VC的dataSource方法中,爲section指定1,爲yourIndexArray.count指定itemsInSection –