【问题标题】:OHAttributedlabel truncated last line of a multiline labelOHAttributedlabel 截断多行标签的最后一行
【发布时间】:2014-01-10 08:42:03
【问题描述】:

我正在使用OHAttributed 标签。我希望如果标签长于 3 行,则第三行以 "..." 结尾。

首先,我像这样计算了我的OHAttributedlabel的框架高度。

    OHAttributedLabel *lblAppointment = [[OHAttributedLabel alloc]init];      
    lblAppointment.numberOfLines = 0;
    lblAppointment.attributedText = atrAppointment;
    [atrAppointment setFont:[UIFont fontWithName:@"MyriadPro-Regular" size:13]];
    appointmentRect.size.height = [self heightForLabel:atrAppointment];
    lblHeight += appointmentRect.size.height + 5;
    [lblAppointment setFrame:appointmentRect];
    [self addSubview:lblAppointment];

有人可以帮我吗?

【问题讨论】:

  • 已设置UILineBreakModeTailTruncation ?
  • 当我设置它时,它只显示第一行,然后截断它的尾巴

标签: ios iphone objective-c uilabel nsattributedstring


【解决方案1】:

尝试将换行模式设置为UILineBreakModeTailTruncation

检查一下

OHAttributedLabel *lblAppointment = [[OHAttributedLabel alloc]init];      
lblAppointment.numberOfLines = 3;
lblAppointment.lineBreakMode=UILineBreakModeTailTruncation;
lblAppointment.attributedText = atrAppointment;
[atrAppointment setFont:[UIFont fontWithName:@"MyriadPro-Regular" size:13]];
appointmentRect.size.height = [self heightForLabel:atrAppointment];
lblHeight += appointmentRect.size.height + 5;
[lblAppointment setFrame:appointmentRect];
[self addSubview:lblAppointment];

【讨论】:

  • 你设置numberOfLines=3; ?
  • 是的,我将它设置为 3 :)
【解决方案2】:

您可以使用字符串绘图选项NSStringDrawingTruncatesLastVisibleLineNSStringDrawingUsesLineFragmentOrigin 来绘制字符串,而不是使用OHATTributedLabel。这些绘图选项可以满足您的需求。

【讨论】:

    猜你喜欢
    • 2013-11-30
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2013-04-12
    • 2011-01-31
    相关资源
    最近更新 更多