How to make text in a UITableViewCell wordwrap?
I have a grouped UITableView with a few sections. The text in some of t开发者_运维技巧he cells can get quite long, I was wondering how I could make the text word-wrap?
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:
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
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.
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
精彩评论