UITableViewCell dynamic height programmatically

This question already has an answer here:


ANSWERS:


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;

}

You can use delegate method

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

in above method you can return one CGFloat variable which have dynamic height of cell for particular index of UITableView


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

UIFont *font = [UIFont systemFontOfSize:20];
NSDictionary *userAttributes = @{NSFontAttributeName: font,
                                 NSForegroundColorAttributeName:     [UIColor blackColor]};
NSString *text = @"Your label text";

CGSize textSize = [text sizeWithAttributes: userAttributes];

ht = 20;

if (textSize.width > [FunctionUtils getViewWidth]) {

    ht = (textSize.width/([FunctionUtils getViewWidth]));
    ht = (ceil(ht))*20+35;
//20 font size
}

return ht;
}


 MORE:


 ? Dynamic UITableCellView height
 ? Dynamic UITableCellView height
 ? Dynamic UITableCellView height
 ? Dynamic UITableCellView height
 ? Dynamic UITableCellView height with cell indicator
 ? Dynamic UITableCellView height with cell indicator
 ? UITableView dynamic cell height breaks on transition or rotation
 ? UITableViewCell dynamic height breaks after insert row
 ? iOS8 implementing heightForRowAtIndexPath with dynamic heights
 ? Dynamic cell height issue with UITableViewCell autolayout jerk while scrolling