gpt4 book ai didi

ios - 如何设计不同的收集单元

转载 作者:可可西里 更新时间:2023-11-01 02:10:07 24 4
gpt4 key购买 nike

我有一个具有不同 collectionCellcollectionView,我想根据单元格设置比例/高度/大小。我该怎么做 ?

这是我的不同单元格的图像:一个 title cell 和 2 个不同的 cell image。一个是 View 的宽度/3,另一个是/2。我不能在 Storyboard中使用自动布局约束来做到这一点,所以我需要在代码中做。我正在尝试使用 collectionViewLayout。

CollectionView

最佳答案

实现

MyViewController 类:UIViewController、UICollectionViewDataSource、UICollectionViewDelegate、UICollectionViewFlowLayout

ViewDidLoad

collectionView.delegate = self;
collectionView.datasource = self;

添加流布局委托(delegate)

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 2{
return CGSize(self.view.frame.size.width / 3, 100)
}

else{
return CGSize(self.view.frame.size.width / 2, 100)
}
// return the size you what
}

关于ios - 如何设计不同的收集单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41219569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com