I have a grouped UITableView with a few sections. The text in some of the cells can get quite long, I was wondering how I could make the text word-wrap?
Asked
Active
Viewed 8,980 times
4 Answers
10
eg
textLabel.numberOfLines = 0;
You can set this to a fixed number of lines if you prefer. It may be a good idea to set the lineBreakMode, and you will probably need to implement:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
using:
NSString sizeWithFont:constrainedToSize:

Paul Lynch
- 19,769
- 4
- 37
- 41
5
You'll have the specify the number of lines the text will use. Setting it to zero will wrap it automatically.
cell.textLabel.numberOfLines=0; // line wrap

Vincent
- 4,342
- 1
- 38
- 37
2
set numberOfLines > 1 on your label and set an appropriate lineBreakMode as well. You might need to modify the frame of the label to have enough space. You can do this in tableView:willDisplayCell:forRowAtIndexPath: of your table view delegate.

Elfred
- 3,851
- 22
- 16
1
It looks like this question Custom Cell Height, right? I don't really get what word-wrap do, but I assume that you want to change the cell size according to the text length, is that right? So you can look at the above question and answer
-
Setting the cell height larger does not make the text fit. It still presents the "..." to the truncated text. – Sheehan Alam May 25 '10 at 16:03
-
"There is one label in the cell whose text is a NSString object and the length of string could be variable , due to this i cannot set a constant height to the cell in UITableViews : heightForCellAtIndex method. " (copied from the question), how about putting it into some UILabel and try again? – vodkhang May 25 '10 at 16:09
-
If I set the label property on the cell I can make it wordwrap. If the frame of the label exceeds the size of the cell, then I need to define a custom cell height. I guess both changes need to be made :) – Sheehan Alam May 25 '10 at 16:14