UICollectionView中的單元間距如何在UICollectionView?我知道有一項財產minimumInteritemSpacing我已將其設置為5.0,但間距仍未出現5.0。我已經實現了流出委托方法。- (CGFloat)collectionView:(UICollectionView *)collectionView layout:
(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 5.0;}不過,我并沒有達到預期的效果。我認為這是最小間距。我沒有辦法設定最大間距嗎?
3 回答

明月笑刀無情
TA貢獻1828條經驗 獲得超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貢獻1829條經驗 獲得超4個贊
minimumLineSpacing
minimumInterItemSpacing
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init]; flow.itemSize = CGSizeMake(cellWidth, cellHeight); flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;flow.minimumInteritemSpacing = 0;flow.minimumLineSpacing = 0;
- 3 回答
- 0 關注
- 1024 瀏覽
添加回答
舉報
0/150
提交
取消