gpt4 book ai didi

ios - 如何在流程布局中有不同的单元格大小

转载 作者:行者123 更新时间:2023-11-28 08:39:26 25 4
gpt4 key购买 nike

这是我可以通过教程做到的

This is the Screenshot of the app

但我必须将第一个和每个第三个单元格设置为全宽。我应该怎么做?

代码是这样的

class MainViewController: UICollectionViewController
{

// data source
let publishers = Publishers()

private let leftAndRightPaddings: CGFloat = 32.0
private let numberOfItemsPerRow: CGFloat = 2.0
private let heigthAdjustment: CGFloat = 100

// MARK: - View controller life cycle

override func viewDidLoad() {
super.viewDidLoad()

let width = (CGRectGetWidth(collectionView!.frame) - leftAndRightPaddings) / numberOfItemsPerRow
let layout = collectionViewLayout as! UICollectionViewFlowLayout
layout.itemSize = CGSizeMake(width, heigthAdjustment)
print(width.description)

}

// MARK: - UICollectionViewDataSource

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return publishers.numberOfPublishers
}

private struct Storyboard
{
static let CellIdentifier = "PublisherCell"
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath: indexPath) as UICollectionViewCell

return cell}

}

最佳答案

您需要在 UICollectionViewDelegateFlowLayout 中实现此 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize 方法

关于ios - 如何在流程布局中有不同的单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36773571/

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