2016-09-30 10 views
0

私はUICollectionViewカスタム高さと幅を持っていますが、私はアプリを起動すると、画面に最初に表示されるすべてのセルは、私の与えた高さと幅に関して完全に設定されますが、セル幅。ここでHere is the screenshotUICollectionViewセル幅の問題

は間隔など、高さと幅を設定するためのメソッドです

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 5.0; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 5.0f; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.collectionView setNeedsLayout]; 
    [self.collectionView layoutIfNeeded]; 
    CGFloat width = self.collectionView.frame.size.width; 
    return CGSizeMake((width/2)-5, 220); 
} 


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 
    return [listOfRetailers_ count]; 
} 
-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ 
    BDRetailerCollectionViewCell *newCell = (BDRetailerCollectionViewCell*)cell; 
    UIFont *font = newCell.brandName.font; 
    [newCell.brandName setFont:[font fontWithSize:12]]; 
    [newCell setNeedsLayout]; 
    [newCell layoutIfNeeded]; 

} 

答えて

0

私はそれを解決した。この方法

(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
[self.collectionView setNeedsLayout]; 
[self.collectionView layoutIfNeeded]; 
+0

が、あなたの答えのための任意の方法のおかげで、この行を削除します。 –

関連する問題