更新时间:2023-11-30 15:26:34
对于动态 tableViewCell 高度使用这个.
For dynamic tableViewCell height use this.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize labelHeight = [self heigtForCellwithString:yourLabel.text withFont:yourLabel.font];
return labelHeight.height; // the return height + your other view height
}
-(CGSize)heigtForCellwithString:(NSString *)stringValue withFont:(UIFont)font{
CGSize constraint = CGSizeMake(300,9999); // Replace 300 with your label width
NSDictionary *attributes = @{NSFontAttributeName: font};
CGRect rect = [stringValue boundingRectWithSize:constraint
options: (NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:attributes
context:nil];
return rect.size;
}