开发者

How can I make a multiline label in a UITableView?

开发者 https://www.devze.com 2022-12-11 23:30 出处:网络
How can we make 开发者_StackOverflow中文版the text in the label of a table view go to the next line?//This allows for multiple lines

How can we make 开发者_StackOverflow中文版the text in the label of a table view go to the next line?


//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.


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

@"Hello,\nworld!"


you can try to use cell with subtitle( initWithStyle:UITableViewCellStyleSubtitle ). if it is not exactly what you want, you can customize your cell by adding UITextView(or, maybe, several UILabels) to it as a subView(s).

0

精彩评论

暂无评论...
验证码 换一张
取 消