0
点赞
收藏
分享

微信扫一扫

比较精确的计算文字高度的api.................

mafa1993 2023-05-09 阅读 104


-(CGFloat)height:(NSString *)Str{

    UILabel *testLabel = [UILabel new];
    testLabel.text = Str;
    [testLabel setNumberOfLines:2];
    [testLabel setFont:[UIFont systemFontOfSize:14]];
    CGSize size = [testLabel sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, MAXFLOAT)];
    NSLog(@"%@",NSStringFromCGSize(size));
    return size.height;
}



举报

相关推荐

0 条评论