如何给UILabel设置行间距

NSString *string = @"方舟子近日向北京市工商行政管理局朝阳分局举报罗永浩的锤子科技公司对产品 Smartisan T1 型号手机进行涉嫌虚假的广告宣传,并请求查实并进行依法处罚。方舟子称,锤子手机在其广告中自吹东半球最好用的手机”“世界顶尖的设计”“一切都是最好的,违反《广告法》第二章第七条第三款使用国家级、最高级、最佳等用语。肆意贬低同类产品,违反第二章第十二条广告不得贬低其他生产经营者的商品或者服务。第三章第二十一条广告主、广告经营者、广告发布者不得在广告活动中进行任何形式的不正当竞争。”";


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 300, 0)];

    label.backgroundColor = [UIColor clearColor];

    label.numberOfLines = 0;

    

    NSMutableAttributedString* text =[[NSMutableAttributedString alloc]initWithString:string];

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

    

    //设置行距

    [paragraphStyle setLineSpacing:15.0f];

    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];

    

    //设置一定Range区间文字颜色

    [text addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 30)];

    //设置一定Range区间文字下划线

    [text addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, 30)];

    

    label.attributedText = text;

    [self.view addSubview:label];

    [label sizeToFit];



效果如下

如何给UILabel设置行间距