0

各行に3つのセルが含まれているコレクションビューがあります。連続して3つのセルがない場合、セルは中央に揃えられます。私はそれらを左に整列させたい。これをどのように達成するのですか?Xcode UICollectionviewセルの左揃え

下の画像は私の問題を示しています。セル4を左に揃えるにはどうすればよいですか?

- (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 

} 

は、事前にありがとう:

enter image description here

これは、現在のコードである私は、コントロールのサイズやインセットを持っています。

+1

確かにこの動作は 'UICollectionViewFlowLayout'の標準的な動作ですか? –

+0

@RoboticCat、標準的な動作として、コレクションビューのセルは常に左から開始します。 – 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 

} 
関連する問題