I have implemented TableView with CustomCell in my app,
I want dynamic height of my UITableViewCell
according to text length in UITableViewCell
,
here is the snapshot of Customcell
:
and here is the snapshot of my UITableView
:
code snippet for heightForRowAtIndexPath
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [DescArr objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 100.0);
return height;
}
As you can see in the 2nd image, height for cell is fixed, it doesn't change with it's text (content) size.
Where am I making mistake? How can I make a a label or a cell to update its size according to its contents/text?
The following code worked fine for me.Try with this
Try to add the following code in your customcell class autolayout method
Try to set the label properties like the following