尽管我设置了 label.numberOfLines = 0,UILabel 仅显示文本的第一行
我创建了自定义 UITableViewCell。
@interface AnswerCell : UITableViewCell
@property (nonatomic, retain) IBOutlet UILabel *textLabel;
@property (nonatomic, retain) IBOutlet UILabel *detailTextLabel;
@end
并设置detailTextLabel.numberOfLines = 0;
cell = [tableView dequeueReusableCellWithIdentifier:kAnswerIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"AnswerCell" owner:self options:nil];
cell=answerCell;
}
cell.detailTextLabel.text = [self extractText:indexPath forLabelAttribute:kDetailTextLabel];
cell.detailTextLabel.font = [self extractFont:indexPath forLabelAttribute:kDetailTextLabel];
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 0;
UILabel 仅显示文本的第一行。但为什么?
更新:我的detailTextLabel 的高度= 21。我需要做什么?我需要改变高度=1000吗?
I created custom UITableViewCell.
@interface AnswerCell : UITableViewCell
@property (nonatomic, retain) IBOutlet UILabel *textLabel;
@property (nonatomic, retain) IBOutlet UILabel *detailTextLabel;
@end
and set detailTextLabel.numberOfLines = 0;
cell = [tableView dequeueReusableCellWithIdentifier:kAnswerIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"AnswerCell" owner:self options:nil];
cell=answerCell;
}
cell.detailTextLabel.text = [self extractText:indexPath forLabelAttribute:kDetailTextLabel];
cell.detailTextLabel.font = [self extractFont:indexPath forLabelAttribute:kDetailTextLabel];
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 0;
UILabel shows only first line of the text. But why?
UPDATE: My detailTextLabel's height = 21. What do I need to do? Do I need to change height = 1000?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你无法显示所有文本,因为标签高度太小。您需要根据文本长度设置所需的高度。
请参阅根据文本调整 UILabel 高度的答案
I guess you cannot show all text because label height is too small. You need to set required height depending on the text length.
See answer for Adjust UILabel height depending on the text
您需要调整 UILabel 的大小..使用 - 计算其高度
,然后相应地调整其大小,
您可能需要更改字体及其大小
You need to resize your UILabel .. calculate its height using -
and then resize it accordingly
you may need to change font and its size
如果您有标签的宽度,请使用以下方法获取显示字符串所需的字符串大小,
并将该大小设置为标签。
Apple 文档可以在此处查看。
If you have the width of the label, get the size of the string that would be required to show the string using the following method,
And set the size to the label.
The Apple documentation can be seen here.