ios中设置文章内容的行间距

 _contentLabel = [[UILabel alloc]init];

        NSString *content = @"产品一枚,也是抖音的用户,选择什么软件来看自己需要的是用户的自由";

        CGFloat width = [UIScreen mainScreen].bounds.size.width;

        _contentLabel.frame = CGRectMake(30*DJScaleScreenRation, 30*DJScaleScreenRation+20+10,width-20*DJScaleScreenRation-58*DJScaleScreenRation-20*DJScaleScreenRation-30*DJScaleScreenRation, 100);

        _contentLabel.numberOfLines = 0;

        _contentLabel.font = [UIFont systemFontOfSize:30*DJScaleScreenRation];

        _contentLabel.textColor = [UIColor colorWithRed:57.0/255 green:57.0/255 blue:57.0/255 alpha:1];

        _contentLabel.textAlignment = NSTextAlignmentLeft;

        _contentLabel.lineBreakMode = NSLineBreakByWordWrapping;

        [_contentLabelsetAttributedText:[selfsetContent:content]];

        //_contentLabel.backgroundColor = [UIColor redColor];

        [_contentLabel sizeToFit];

        [self addSubview:_contentLabel];


- (NSMutableAttributedString *)setContent:(NSString *)content

{


    NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:content];


    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];

    [paragraphStylesetLineSpacing:2.5];//设置行间距

    [attributedStringaddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, [contentlength])];

    returnattributedString;

}

你可能感兴趣的:(ios中设置文章内容的行间距)