Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a multiline label in a UITableView?

How can we make the text in the label of a table view go to the next line?

like image 339
pramuk Avatar asked Nov 27 '22 15:11

pramuk


2 Answers

//This allows for multiple lines
cell.textLabel.numberOfLines = 0;
//This makes your label wrap words as they reach the end of a line
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;

Also, if you want your label to have more room for such multiple lines, you probably should allow for table rows with greater height. You can do this either by overriding

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

and returning your custom height for each row there, or by specifying your table's rowHeight property, giving the common height of each row.

like image 132
luvieere Avatar answered Dec 19 '22 01:12

luvieere


Try adding "\n" in the label, eg:

@"Hello,\nworld!"
like image 41
fbrereto Avatar answered Dec 19 '22 01:12

fbrereto