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?
A:
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
vodkhang
2010-05-25 15:41:10
Setting the cell height larger does not make the text fit. It still presents the "..." to the truncated text.
Sheehan Alam
2010-05-25 16:03:43
"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
2010-05-25 16:09:30
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
2010-05-25 16:14:23
Yeah, I think so:)
vodkhang
2010-05-25 16:24:46
A:
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
2010-05-25 15:52:55
+1
A:
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
2010-05-25 16:27:16