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];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容