문제

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