Custom UITableView Dynamic Cell Height

前端 未结 6 640
一个人的身影
一个人的身影 2021-02-06 09:22

I have search and searched through endless blogs and articles on how to determine a dynamic height for a custom UITableViewCell and its detailed text. I have really had a hard t

6条回答
  •  广开言路
    2021-02-06 09:41

    iOS 7

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
    {
        NSString *text = @"Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello HelloHello HelloHello HelloHello HelloHello HelloHello Hello";
    
        CGRect rect = [text boundingRectWithSize:CGSizeMake(280.0f, CGFLOAT_MAX) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{
            NSFontAttributeName: [UIFont fontWithName:@"Hellvetica" size:14.0f]
        } context:nil];
    
        return CGSizeMake(320.0f, ceil(rect.size.height) + 10.0f);
    }
    

提交回复
热议问题