尽管我设置了 label.numberOfLines = 0,UILabel 仅显示文本的第一行

发布于 2024-12-26 22:17:01 字数 964 浏览 2 评论 0原文

我创建了自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寻梦旅人 2025-01-02 22:17:01

我猜你无法显示所有文本,因为标签高度太小。您需要根据文本长度设置所需的高度。

请参阅根据文本调整 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

坏尐絯℡ 2025-01-02 22:17:01

您需要调整 UILabel 的大小..使用 - 计算其高度

[contentsStr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] 

,然后相应地调整其大小,

您可能需要更改字体及其大小

You need to resize your UILabel .. calculate its height using -

[contentsStr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] 

and then resize it accordingly

you may need to change font and its size

剪不断理还乱 2025-01-02 22:17:01

如果您有标签的宽度,请使用以下方法获取显示字符串所需的字符串大小,

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)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,

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size

And set the size to the label.

The Apple documentation can be seen here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文