2016-09-30 91 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

我已經解決了,但感謝你的回答任何方式刪除此行。 –