Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it without subclassing <code>UITableViewCell</code>.</p> <p>In the method <code>tableView:cellForRowAtIndexPath:</code>, create a basic <code>UITableViewCell</code> and change the properties of the <code>UILabel</code> contained in this cell. Change the maximum number of lines to fit more text in your cell. </p> <p>Unfortunately, the label of the cell is not accessible by properties, so you need to fetch it with the <code>subviews</code> property.</p> <p>Of course this uses an implementation detail of <code>UITableViewCell</code>, so it might break with future releases of the SDK. Use with care.</p> <p>Here is an example:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"YourCellId"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"YourCellId"] autorelease]; cell.font = [UIFont systemFontOfSize:16]; UILabel* cellLabel = [cell.contentView.subviews objectAtIndex:0]; [cellLabel setNumberOfLines:3]; } cell.text = @"Your text"; return cell; } </code></pre> <p><strong>Update:</strong></p> <p>To set the row height to fit the text, you can do the following:</p> <p><em>1. Set the cell height to fit the text.</em></p> <p>You need something like this:</p> <pre><code>CGSize textSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(313, 1000) lineBreakMode:UILineBreakModeWordWrap]; cell.frame = CGRectMake(0.0f, 0.0f, 320.0, textSize.height); </code></pre> <p><em>2. Return the cell height in the <code>tableView:heightForRowAtIndexPath:</code> method.</em></p> <p>For example like this:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [self tableView:(UITableView*)self.view cellForRowAtIndexPath:indexPath]; CGRect cellFrame = cell.frame; return cellFrame.size.height; } </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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