Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text in a UITableViewCell wordwrap?

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?

like image 952
Sheehan Alam Avatar asked Dec 02 '22 05:12

Sheehan Alam


2 Answers

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:
like image 151
Paul Lynch Avatar answered Dec 11 '22 17:12

Paul Lynch


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
like image 29
Vincent Avatar answered Dec 11 '22 16:12

Vincent