美文网首页
UILabel设置行间距

UILabel设置行间距

作者: YNTCode | 来源:发表于2016-07-01 17:28 被阅读741次

    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设置行间距

          本文链接:https://www.haomeiwen.com/subject/owzfjttx.html