大家好,我正在尝试根据UITextView的文本长度来扩展我的collectionView单元格。
为此,我决定实现方法boundingRectWithSize
,但是当我运行代码时,控制台始终将高度返回0。
我不明白我哪里错了...因为高度始终为0?
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
SlideMenuCollectionViewCell *cell = (SlideMenuCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
CGSize size = CGSizeMake(collectionView.frame.size.width, 1000);
NSDictionary *attr = @{ NSFontAttributeName : [UIFont systemFontOfSize:12]};
CGRect extimate = [cell.subtitleCell.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:attr context:nil];
NSLog(@"%f", extimate.size.height);
return CGSizeMake(collectionView.frame.size.width, extimate.size.height);
}
我的安慰
2018-09-26 19:00:07.882366+0200[3676:1020208] 0.000000
2018-09-26 19:00:07.882556+0200[3676:1020208] 0.000000
2018-09-26 19:00:07.882657+0200[3676:1020208] 0.000000
2018-09-26 19:00:07.882742+0200[3676:1020208] 0.000000