Reputation: 1113
The sizeToFit
method of UILabel
doesn't apply in cellForRowAtIndexPath
.
The problem is I need some of my cells to look like this:
and others to look like this:
What's the solution for this?
Thanks
Upvotes: 2
Views: 442
Reputation: 2383
I had the same problem and I solved this way:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIFont *font = [UIFont fontWithName:@"Roboto-Regular" size:14];
CGSize textSize = [[eventDetails objectForKey:[detailTitle objectAtIndex: indexPath.row]] sizeWithFont:font];
CGFloat strikeWidth = textSize.width;
if(strikeWidth <280) // if the length is lower than max width
{
return 30; // normal height of cell
}
else
{
return 30 + ((int) strikeWidth/280 )*15;// if not give the cell the height you want
}
}
And do not forget to set the number of lines of label to 0 [label setNumberOfLines:0];
Upvotes: 0
Reputation: 1113
The sizeToFit method does what it is supposed to do in the cellForRowAtIndexPath method after disabling auto layout in the storyboard.
Upvotes: 1