2016-06-07 121 views
0

在我的应用程序中,我使用的是使用UICollectionView。我想在UICollectionViewCell之间设置修复空间。所以我该怎么做?如何保持uicollectionview单元格之间的间距

这里是我的代码:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { 
    return 20 

} 

通过这条线,我可以设置单元格之间的空间?

这是我的截图请看看这个。让我知道我可以设置固定的距离在两个横向或纵向模式

enter image description here enter image description here

+1

[UICollectionView中的单元格间距]的可能重复(http://stackoverflow.com/questions/17229350/cell-spacing-in-uicollectionview) –

回答

1

也许,你需要执行如下方法。

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section; 
1

您可以通过故事板敏调整UICollectionCell之间的间距。间距 UICollectionView的属性。

enter image description here

在这里,可以设置电池和线路最小间距值。

希望它能帮助你。

0

大小检查如果你想在细胞之间exact间距你需要计算规模为细胞,将最适合允许管理间距在考虑sectionInsets和CollectionView bounds时,您需要的间距不需要包装。例如。

let desiredSpacing: CGFloat = 20.0 

if let layout = self.collectionView?.collectionViewLayout as? UICollectionViewFlowLayout { 
    layout.minimumLineSpacing = desiredSpacing 
    let totalCellsContentWidth = self.collectionView!.bounds.width - layout.sectionInset.left - layout.sectionInset.right 
    let numberOfCellsPerRow: CGFloat = 10 
    let numberOfSpacesPerRow = numberOfCellsPerRow - 1 
    let cellWidth = (totalCellsContentWidth - (numberOfSpacesPerRow * desiredSpacing)/numberOfCellsPerRow) 
    layout.itemSize = CGSize(width: cellWidth, height: cellWidth) 
} 

假设你的细胞大小相同的minimumLineSpacing很简单,但原本扩大包装到下一行之前,以适应该行的最大细胞。正如你所看到的那样,单元格间距有点复杂。

相关问题