2015-10-06 104 views

回答

0

試試這個:

// Configure layout 
     UICollectionViewFlowLayout *flowLayout_D = [[UICollectionViewFlowLayout alloc] init]; 
     [flowLayout_D setItemSize:CGSizeMake(102, 96)]; //your cell size 
     [flowLayout_D setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 
     [self->mycollectionView setCollectionViewLayout:flowLayout_D]; 

,你必須委託方法來更改間距:

#pragma mark Collection view layout things 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { 
    if (collectionView==myCollectionView) { 
    return 2.0; 
    } 
    else 
     return 0; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { 
    if (collectionView==myCollectionView) { 
     return 2.0; 
    } 
    else 
     return 0; 
} 

你也可以改變邊緣插圖:

// Layout: Set Edges 
- (UIEdgeInsets)collectionView: 
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { 
    // return UIEdgeInsetsMake(0,8,0,8); // top, left, bottom, right 
    if (collectionView==myCollectionView) { 
    return UIEdgeInsetsMake(0,0,0,0); 
    }// top, left, bottom, right 
    else 
     return UIEdgeInsetsMake(0,0,0,0); 

} 
+0

我無法從邊緣提供邊距。 – TechGuy

+0

您可以使用邊緣插入邊距,儘管它不直觀地顯示任何邊距。 Contnetn將在一些填充後放置。 –

相關問題