UITABLEVIEW DYNAMIC CELL HEIGHT
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
int width = 300; // width of your label
return ([Self calculateHeightOfString:@"Your String" withFont:[UIFontsystemFontOfSize:15] ofWidth:width withLineBreak:NSLineBreakByWordWrapping]+30);
}
// Method to calculate height
-(float)calculateHeightOfString:(NSString *)str withFont:(UIFont *)font ofWidth:(float)width withLineBreak:(NSLineBreakMode)line
{
//NSLog(@"%s",__PRETTY_FUNCTION__);
CGSize suggestedSize = [str sizeWithFont:font constrainedToSize:CGSizeMake(width,FLT_MAX) lineBreakMode:line];
return suggestedSize.height;
}
No comments:
Post a Comment