[英]How to make text fit in UITableViewCell is iOS7?
I have a UILabelCell but don't know how to make all the text in that label fit (sometimes it overruns). 我有一个UILabelCell,但不知道如何使该标签中的所有文本都适合(有时会溢出)。 Any ideas of how I could resize the text in iOS7 (all the solutions are for previous OS'es that don't work with iOS7 because the methods are deprecated...) 关于如何在iOS7中调整文本大小的任何想法(所有解决方案均适用于不支持iOS7的先前操作系统,因为该方法已弃用...)
Here is the code for making the cell: 这是制作单元的代码:
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.textLabel.text = text;}
I'm assuming you mean allow the text to overflow onto multiple lines? 我假设您的意思是允许文本溢出到多行上? You can use the numberOfLines
property which is 1 by default. 您可以使用默认为1的numberOfLines
属性。
cell.textLabel.numberOfLines = 0;
0 signifies an unlimited number of lines. 0表示行数不受限制。
The caveat is you'll also need to provide a taller height in tableView:heightForRowAtIndexPath:
if there are too many lines to fit in whatever height you're using (or the default height). 需要注意的是,您还需要在tableView:heightForRowAtIndexPath:
提供更高的高度tableView:heightForRowAtIndexPath:
如果有太多行无法容纳您正在使用的任何高度(或默认高度)。
Try adding this: 尝试添加以下内容:
cell.textLabel.adjustsFontSizeToFitWidth = YES;
(I'm assuming you want it to fit on one line in the available space.) (我假设您希望它适合可用空间中的一行。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.