UICollectionView中的单元间距如何在UICollectionView?我知道有一项财产minimumInteritemSpacing我已将其设置为5.0,但间距仍未出现5.0。我已经实现了流出委托方法。- (CGFloat)collectionView:(UICollectionView *)collectionView layout:
(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 5.0;}不过,我并没有达到预期的效果。我认为这是最小间距。我没有办法设定最大间距吗?
3 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
覆盖标准流布局。 添加这样的实现: - (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect { NSArray *answer = [super layoutAttributesForElementsInRect:rect]; for(int i = 1; i < [answer count]; ++i) { UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i]; UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1]; NSInteger maximumSpacing = 4; NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame); if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) { CGRect frame = currentLayoutAttributes.frame; frame.origin.x = origin + maximumSpacing; currentLayoutAttributes.frame = frame; } } return answer;}
三国纷争
TA贡献1804条经验 获得超7个赞
minimumLineSpacing
minimumInterItemSpacing
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init]; flow.itemSize = CGSizeMake(cellWidth, cellHeight); flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;flow.minimumInteritemSpacing = 0;flow.minimumLineSpacing = 0;
- 3 回答
- 0 关注
- 1648 浏览
添加回答
举报
0/150
提交
取消