![](/img/trans.png)
[英]How to display particular section cells/items in centre horizontally in Collectionview Swift
[英]How to make a collectionView with resizable cells horizontally in swift
我想創建一個具有不同大小的單元格的集合視圖。 我的最終結果是這樣的照片
。
您的類還需要實現UICollectionViewDelegateFlowLayout
協議。 初始化集合視圖,如下所示:
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.delegate = self
然后可以實現功能sizeForItemAt
:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = // get the width
let height = // get the height
return CGSize(width: width, height: height)
}
只要您的屏幕可以容納多個寬度,集合視圖就會自動將它們水平放置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.