Inside your function cellForRowAtIndexPath :. The first time you create your cell:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; cell.textLabel.numberOfLines = 0; cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21.0]; }
You will notice that I also set the number of lines for the label to 0. This allows you to use as many lines as needed.
You also need to indicate how large your UITableViewCell , so do this in your heightForRowAtIndexPath function:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellText = @"some text which is part of cell display"; UIFont *cellFont = [UIFont fontWithName:@"HelveticaNeue" size:21.0]; CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT); CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; int buffer = 10; return labelSize.height + buffer; }
I added an extra 10 to my cell height because I like the small buffer around my text.
UPDATE: If the result looks too tight and clumpsy, then do it -
[cell.textLabel setMinimumFontSize:13.0]; [cell.textLabel setAdjustsFontSizeToFitWidth:NO];
This should solve your problem.
source share