我已经看到很多方法可以在UICollectionView中获取轮播/一行/节。但非工作可能,你有办法。
我有以下内容:
@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!)
}
答案 0 :(得分:0)
好的 - 足够简单:
layout.itemSize = CGSize(width: (self.view.frame.size.width/2)+50, height: (self.view.frame.size.height/2)+50)
对于更复杂的细胞:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: 100, height: 100)
}