我有一个带动态单元的视图集。
我发现Cell a / c的高度为Text Supplied:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath: (NSIndexPath *)indexPath
{
CGFloat cellWidth = (self.mCollectionView.frame.size.width-7)/7;
CGFloat hegiht = [calendar getTheSizeForText:[dataArray objectAtIndex:indexPath.row] toFitInWidth:cellWidth];
return CGSizeMake(cellWidth,
hegiht) ;
}
// FInding Height
+ (CGFloat)getTheSizeForText:(NSString *)text toFitInWidth:(CGFloat)width
{
CGRect textRect = [text boundingRectWithSize:CGSizeMake(width-2*kPadding, 999)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}
context:nil];
CGFloat cellHeight = textRect.size.height+10+21 ; //5 top padding 5
bottom 21 is the height of another label which is fied
return cellHeight;
}
现在,当我运行我的应用程序时,我正在获取屏幕:
我的细胞高度不均匀。获得统一身高的最佳方法是什么。