Pergunta

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

Foi útil?

Solução

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

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top