我正在使用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];
有人可以帮我吗?
答案 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)
您可以使用字符串绘图选项OHATTributedLabel
和NSStringDrawingTruncatesLastVisibleLine
来绘制字符串,而不是使用NSStringDrawingUsesLineFragmentOrigin
。这些绘图选项可以为您提供您想要的内容。