集合视图单元格从左到右显示不正确。它在中心有差距。我如何纠正此问题。
collectionView_.register(UINib.init(nibName: String(describing: GoalSelectionCollectionViewCell.self), bundle: nil), forCellWithReuseIdentifier: reuseIdentifier)
collectionView_.allowsMultipleSelection = true
if let flowLayout = collectionView_?.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemSize:CGSize = CGSize(width: 80.0, height: 30.0);
return itemSize;
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 20.0;
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 20.0;
}
1条答案
按热度按时间aor9mmx11#
您需要符合
UICollectionViewDelegateFlowLayout
,还需要设置minimumLineSpacing
(行之间的最小间距)和minimumInteritemSpacing
(同一行中项目之间的最小间距)