gsdios / SDAutoLayout

One line of code to implement automatic layout. 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库。The most easy way for autoLayout. Based on runtime.
MIT License
5.9k stars 1.28k forks source link

富文本 高度计算错误 #184

Closed OnVo closed 7 years ago

OnVo commented 7 years ago

我用的是UILabel 因为要用到行边距 所以用富文本添加了行边距 让后用autoHeightRatio(0) 进行高度自适应 最后显示出来的高度是没有行边距的高度

代码如下(我用的是自带的UITableViewCell cell.textLabel): cell.textLabel.textColor = [UIColor colorWithHexString:@"7d7d7d"]; cell.textLabel.numberOfLines = 0; cell.textLabel.font = [UIFont systemFontOfSize:14]; cell.textLabel.text = [NSString stringWithFormat:@"%@\n%@\n%@", @"1.工作日15:00前提现,24小时内到账;", @"2.工作日15:00后提现,下个工作日12:00前到账;", @"3.非工作日提现请求,顺延到下个工作日提现到账"];

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:cell.textLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
    cell.textLabel.attributedText = attributedString;

    cell.textLabel.sd_layout
    .topSpaceToView(cell.contentView, 15)
    .autoHeightRatio(0);
gsdios commented 7 years ago

富文本设置下label的isAttributedContent为YES