OHAttributedlabel截断了多行标签的最后一行

时间:2014-01-10 08:42:04

标签: ios iphone objective-c uilabel nsattributedstring

我正在使用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];

有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

尝试将设置换行符模式设为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];

答案 1 :(得分:0)

您可以使用字符串绘图选项OHATTributedLabelNSStringDrawingTruncatesLastVisibleLine来绘制字符串,而不是使用NSStringDrawingUsesLineFragmentOrigin。这些绘图选项可以为您提供您想要的内容。