作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然我有自己的自定义布局,但我的单元格仍然有一点间距。我试图在每行中放置 7 个项目,但我总是得到 6 个带有一堆间距的项目。
这是我的布局:
class monthFlow: UICollectionViewFlowLayout, UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: collectionView.frame.size.width/7, height: collectionView.frame.size.height/8)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
但它看起来像这样:
最佳答案
这很正常。 UICollectionViewFlowLayout 的内置行为是将单元格均匀地分布在屏幕上(完全合理)。如果你不想要那样,你将不得不做比你在 UICollectionViewFlowLayout 子类中做的更多的事情来改变行为 - 你需要覆盖 layoutAttributesForElementsInRect:
和 layoutAttributesForItemAtIndexPath:
。
事实上,从您目前展示的代码来看,一开始就没有必要继承 UICollectionViewFlowLayout; 您所做的一切都可以通过设置布局属性来完成。但是要将完全对齐更改为左对齐,您确实需要子类化。
您甚至可以考虑编写自己的 Collection View 布局不是作为 UICollectionViewFlowLayout 的子类,特别是因为月布局不是流式布局 - 它总是由 7 个单元组成,这不是流布局确实如此。因此,在某种程度上,您在这里的错误是认为您可以做到这一点而无需首先编写自己的布局。
关于ios - swift : The spacing between my cells in my UICollectionView is not zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31394900/
我是一名优秀的程序员,十分优秀!