ios之改变label的行间距

参考地址:http://blog.csdn.net/daiyelang/article/details/45840591

今天看到这篇博客,感觉很有用,亲测可用。代码如下:

    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 300, 200, 60)];

    //label1.text = @"你开心\n我就开心";

    label1.textColor = [UIColor redColor];

    label1.numberOfLines = 2;

    [self.view addSubview:label1];

    

    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:@"你开心\n我就开心"];

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

    [paragraphStyle setLineSpacing:20];

    [attributeString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [@"你开心\n我就开心" length])];

    [label1 setAttributedText:attributeString];

iOS中零碎的知识点太多了,学无止尽!

你可能感兴趣的:(ios,label,行间距)