我有一个UILabelCell,但不知道如何使该标签中的所有文本都适合(有时它会超出)。关于如何在iOS7中调整文本大小的任何想法(所有解决方案都适用于以前的操作系统,因为这些方法已被弃用,因此不适用于iOS7)。
以下是制作单元格的代码:
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.textLabel.text = text;}
答案 0 :(得分:1)
我假设您的意思是允许文本溢出到多行?您可以使用默认为1的numberOfLines
属性。
cell.textLabel.numberOfLines = 0;
0表示无限数量的行。
需要注意的是,如果有太多的线条无法适合您使用的任何高度(或默认高度),您还需要在tableView:heightForRowAtIndexPath:
中提供更高的高度。
答案 1 :(得分:0)
尝试添加此内容:
cell.textLabel.adjustsFontSizeToFitWidth = YES;
(我假设您希望它适合可用空间中的一行。)