views:

64

answers:

2

I have a somewhat long string that gets truncated when displayed in a tablView cell. I did this to make the table view wider:

tableView.rowHeight = 100;

How can I make the font smaller as well as wrap the text in the table view cell?

A: 

You should subclass UITableViewCell and make it have a UITextView instead of a UITextField. Then assign your subclass to your UITableView.

Altealice
+1  A: 

In tableView:cellForRowAtIndexPath: you can set a few properties on the textLabel (or descriptionLabel, depending on what style of cell you're using) to do this. Set font to change the font, linkBreakMode to make it word-wrap, and numberOfLines to set how many lines max (after which point it truncates. You can set that to 0 for no max.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:kMyCellID];
    if( aCell == nil ) {
        aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kMyCellID] autorelease];

        aCell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:10.0];
        aCell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        aCell.textLabel.numberOfLines = 2;  // 0 means no max.
    }

    // ... Your other cell setup stuff here

    return aCell;
}
zpasternack