0

我有一個collectionview,其中每行包含3個單元格。每當沒有連續3個單元格時,單元格將與中間對齊。我想讓他們左轉。我該如何做到這一點?Xcode UICollectionview單元格左對齊

下圖顯示了我的問題。如何將單元格4對齊到左邊?

enter image description here

這是當前的代碼,我有控制尺寸和插圖:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{ 
    return UIEdgeInsetsMake(0, 10, 0, 10); 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    CGRect screenBound = [[UIScreen mainScreen] bounds]; 
    CGSize screenSize = screenBound.size; 
    CGFloat screenWidth = screenSize.width; 
    CGFloat screenHeight = screenSize.height; 

    return CGSizeMake(screenWidth/3-20, 80); //three cells per row 

} 

預先感謝您。

+1

當然這種行爲是'UICollectionViewFlowLayout'的標準行爲嗎? –

+0

@RoboticCat,根據標準行爲,collectionview單元總是從左側開始。 – Maddy

回答

0
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    CGRect screenBound = [[UIScreen mainScreen] bounds] 
     float colum = 3.0; 
    float spacing = 10.0; 
    float value = floorf((Float(screenwith) - (colum - 1) * spacing)/
    colum) 

    return CGSizeMake(value, value); //three cells per row 

}