第18月第19天 masonry等分 uilabel sizetofit

1.masonry等分

mas_distributeViewsAlongAxis

MASAxisTypeHorizontal

 

2.uilabel sizetofit

+(CGSize)labSizeWithStr:(NSString *)_str font:(UIFont *)_font labWidth:(int)_labWidth lineSpacing:(int)_lineSpacing numberOfLines:(int)_numberOfLines{
     
    if (!_str) {
        return CGSizeZero;
    }
 
    UILabel *cLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _labWidth, 0)];
    [cLabel setFont:_font];
    [cLabel setNumberOfLines:_numberOfLines];
     
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:_lineSpacing];
     
    [cLabel setAttributedText:[[NSAttributedString alloc] initWithString:_str attributes:@{NSParagraphStyleAttributeName:paragraphStyle}]];
    [cLabel sizeToFit];
     
    CGSize returnSize = cLabel.size;
    cLabel = nil;
     
    return returnSize;
}

http://blog.51cto.com/liyun2422/1732186

原文地址:https://www.cnblogs.com/javastart/p/8602760.html