UILabel设置行间距

UILabel设置行间距

    _answerLabel = [[UILabel alloc]init];
    _answerLabel.textColor = kXHColor(@"#333333");
    _answerLabel.numberOfLines = 0;
    _answerLabel.preferredMaxLayoutWidth = SCREENWIDTH - pixwn(15) * 2;
    [self.contentView addSubview:_answerLabel];
    //用的masonry布局
    [_answerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.top.equalTo(_userImageBtn.mas_bottom).offset(pixwn(20));
        make.left.equalTo(self).offset(pixwn(15));
        make.right.equalTo(self.mas_right).offset(-pixwn(15));
    }];
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:data];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:pixwn(8)];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [data length])];
    [attributedString addAttributes:@{NSFontAttributeName:[XHFontSize scaleFontSize:19],NSParagraphStyleAttributeName:paragraphStyle1} range:NSMakeRange(0, [data length])];
    [_answerLabel setAttributedText:attributedString];
    [_answerLabel sizeToFit];

你可能感兴趣的:(UILabel设置行间距)