The sizeToFit method of UILabel doesn't apply in cellForRowAtIndexPath.

The problem is I need some of my cells to look like this: enter image description here

and others to look like this: enter image description here

What's the solution for this?

Thanks

有帮助吗?

解决方案

The sizeToFit method does what it is supposed to do in the cellForRowAtIndexPath method after disabling auto layout in the storyboard.

其他提示

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];

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top