gpt4 book ai didi

ios - 居中对齐单个 collectionview 单元格

转载 作者:搜寻专家 更新时间:2023-11-01 05:43:55 38 4
gpt4 key购买 nike

如果只返回单个单元格,我喜欢将 UICollectionview 单元格居中对齐。我正在使用这个

 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

if self.imageSelected.count == 1
{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(0, 100, 0, 0)
}
}

return self.imageSelected.count

}

如果计数为 1,则会选择上面的代码,但我没有看到单元格位置有任何移动。

我也试过了,但是这里甚至没有碰到断点

  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
if self.imageSelected.count == 1 {
return UIEdgeInsetsMake(0, 100, 0, 0)
} else {
return UIEdgeInsetsMake(0, 0, 0, 0)
}
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return self.imageSelected.count

}

最佳答案

将其放入您的 View Controller 中,而不是您问题中的代码:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
if self.imageSelected.count == 1 {
return UIEdgeInsetsMake(0, 100, 0, 0)
} else {
return UIEdgeInsetsMake(0, 0, 0, 0)
}
}

这样您创建的代码就可以工作了。如果您需要关于如何将单元格居中的更准确的答案,请询问,我会花一些时间和精力来帮助您:)

关于ios - 居中对齐单个 collectionview 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39690279/

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