iOS设置label行距

前端之家收集整理的这篇文章主要介绍了iOS设置label行距前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view,typically from a nib.
self.label = [[UILabel alloc] initWithFrame:CGRectMake(90,90,200,90)];
[self.view addSubview:self.label];
self.label.font = [UIFont systemFontOfSize:13];
self.label.numberOfLines = 0;
self.label.text = @"今天是个好日子啊今天是个好日子今天是个好日子啊今天是个好日子今天是个好日子啊今天是个好日子今天是个好日子啊今天是个好日子今天是个好日子啊今天是个好日子今天是个好日子啊今天是个好日子";

//------- 设置行距 -------//
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:self.label.text];;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
[paragraphStyle setLineSpacing:15];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,self.label.text.length)];
self.label.attributedText = attributedString;

}

猜你在找的程序笔记相关文章