Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - Dynamic Label Size Not Returning Properly
    primarykey
    data
    text
    <p>I have spent hours trying to solve this to no success.</p> <p>I am trying to display data on a UITableViewCell in a way that the height gets dynamically adjusted according to the data. </p> <p>Now, the apps seems to work fine with a lot of data but with some data, the label doesn't adjust properly. As you can see, the constrainedToSize functionality has been used which returns the height of the given text. </p> <p>This height is given out incorrectly a lot of times. For example. When the label text is "High - pulsing white, on glidepath - steady white, slightly below glide slope steady red, low - pulsing red." the returned height is 63 when it should be more than that. </p> <p>Another example: "High - pulsing white, on course and on glidepath - steady white, off course but on glidepath - pulsing white and red; low - pulsing red" returns the total label height as 84 when it should be more than that as the label doesn't fit on my tableview at all. </p> <p>A strange thing that I noticed is that the cells that are out of whack usually have sizes 63 or 84... I haven't come across more such sizes but if that could help.. </p> <p>The code:</p> <pre><code>if (tableView.tag ==1) { NSString *cellText; if ([multipleAddressSplit count]==0) { if (indexPath.row ==0) { cellText =[OptionText1 objectAtIndex:i]; } if (indexPath.row == 1) { cellText =[OptionText2 objectAtIndex:i]; } if (indexPath.row == 2) { cellText =[OptionText3 objectAtIndex:i]; } } UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0]; CGSize constraintSize = CGSizeMake(OptionTable.frame.size.width , MAXFLOAT); CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; NSLog(@"========start========="); NSLog(@"Celltext is: %@",cellText); NSLog(@"Method Label %f",(labelSize.height)); NSLog(@" 1/3rd %f",(OptionTable.frame.size.height/3-15)); NSLog(@"=========stop========"); if ((labelSize.height)&lt;((OptionTable.frame.size.height/3)-15)) { NSLog(@" Returned 1/3rd is: %f",(OptionTable.frame.size.height/3)); return (OptionTable.frame.size.height/3); } else { return labelSize.height + 15; } </code></pre> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload