Label适应文字大小

- (CGFloat)infoLbSize
{
    CGSize maxSize = CGSizeMake(self.frame.size.width, MAXFLOAT);
    NSDictionary *attrs = @{NSFontAttributeName : self.infoLb.font};
    // 计算文字占据的高度
    CGSize size = [self.infoLb.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    return size.height;
}


你可能感兴趣的:(项目实用)