Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It would be better to move the resizing calculations to layoutSubviews.</p> <pre><code>//CustomCell.m - (void)layoutSubviews{ CGRect label1Frame = self.label1.frame; //Calculate the size of label 1 CGSize label1Size = [self.label1.text sizeWithFont:[self.label1 font] constrainedToSize:CGSizeMake(label1Frame.size.width,42.0f) lineBreakMode:NSLineBreakByTruncatingTail]; label1Frame.size.height = label1Size.height; CGRect label2Frame = self.label2.frame; //Calculate the size of label 2 CGSize label2Size = [self.label2.text sizeWithFont:[self.label2 font] constrainedToSize:CGSizeMake(label2Frame.size.width,21.0f) lineBreakMode:NSLineBreakByTruncatingTail]; label2Frame.size.height = label2Size.height; //Total height of labels CGFloat totalHeight = label1Frame.size.height+label2Frame.size.height+5.0f; //For centering half of difference of two labels with cell label1Frame.origin.y = (self.frame.size.height - totalHeight)/2.0f; self.label1.frame = CGRectIntegral(label1Frame); label2Frame.origin.y = label1Frame.origin.y+label1Frame.size.height+5.0f; self.label2.frame = CGRectIntegral(label2Frame); </code></pre> <p>}</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ CustomCell1 *cell = (CustomCell1 *)[self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell1" owner:self options:nil]; cell = [nib objectAtIndex:0]; cell.label1.lineBreakMode = UILineBreakModeWordWrap; cell.label1.numberOfLines = 2; cell.label1.tag = [indexPath row]; } cell.label1.text = [[responseArray objectAtIndex:[indexPath row]] text]; if([[[responseArray objectAtIndex:[indexPath row]] isDone] isEqualToString:@"N"]) { cell.label2.text = @""; } else { cell.label2.text = @"Done"; } return cell; } </code></pre>
 

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