gpt4 book ai didi

ios - UICollectionViewCell 大小错误

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

我对 UICollectionViewCell 有疑问。

我的 UICollectionViewCell 的宽度 = UIScreen.main.bounds.size.width 并且在我将 UILabel 添加到单元格之前它工作正常具有左右边缘的约束。如果我只为左边添加就可以了。但是什么时候我都有问题。

错误状态:

Bug enter image description here

正常状态:

enter image description here enter image description here

最佳答案

extension YourViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 50)

}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return .zero
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
}

你可以试试这段代码。在 Storyboard -> UICollectionView -> 在 Size Inspector 中将 Estimate size 更改为 None

关于ios - UICollectionViewCell 大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59058977/

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