[英]Issues with resizing my UICollectionViewCell
我目前正在尝试在我的 CollectionView 中调整单元格的大小。 我已经实现了 dataSource、CollectionViewDelegate 和 CollectionViewDelegateFlowLayout。
这是我为后者提供的代码:
extension ViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout, sizeForItemAt
indexPath: IndexPath) -> CGSize
{
return CGSize(width: 100.0, height: 100.0)
}
}
The problem is that when I head over to my storyboard and select my CollectionView and then go to the Attributes Inspector to switch "Estimate Size" from "Automatic" to "None," I would get three columns after running my app [Image #1 ]。
我正在寻找的结果是能够拥有一个具有更大单元格的中间列,正如我在图像 #2 上显示的那样。
以前有人处理过这个问题吗?
为了将集合视图单元格显示为列表,您可以将单元格宽度更改为集合视图的宽度。 提供恒定宽度不适用于不同的设备尺寸。
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout, sizeForItemAt
indexPath: IndexPath) -> CGSize
{
let width = collectionView.frame.width
return CGSize(width: width, height: 100.0)
}
}
并为内部矩形视图提供所需的约束值以实现所需的外观。 使 collectionView 单元格背景清除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.