I have implemented TableView with CustomCell in my app,
I want dynamic height of my UITableViewCell
according to text length in UITableViewCell
A'm looking for a long time how to determinate cell height properly, - looks like - it's a best solution, boundingRectWithSize and constrainedToSize often incorrectly calculated text height, you need to create UILabel than use sizeThatFits function, see below
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(8, 5, celllabelWidth, 9999)];
label.numberOfLines=0;
label.font = [UIFont fontWithName:fontName size:textSize];
label.text = @"celllabelTextHere";
CGSize maximumLabelSize = CGSizeMake(celllabelWidth, 9999);
CGSize expectedSize = [label sizeThatFits:maximumLabelSize];
return expectedSize.height;
}