获取label当前的文本行数:
@implementation UILabel (Util)
- (NSInteger)cq_lineCount {
CGFloat labelHeight = [self sizeThatFits:CGSizeMake(self.frame.size.width, MAXFLOAT)].height;
NSInteger count = (labelHeight) / self.font.lineHeight;
return count;
}
是否准确?
这种方法对于一般的UILabel.text赋值是准确的(富文本attributedText中修改了行间距段间距是不准的).