label设置行间距,换行剧中方法

// 创建一个Label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 300, 300)];
// 设置为多行显示
label.numberOfLines = 0; 
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// 行间距设置为30
[paragraphStyle setLineSpacing:15];
//[paragraphStyle setAlignment:NSTextAlignmentCenter];//换行居中
NSString *testString = @"设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距设置Label的行间距";
NSMutableAttributedString *setString = [[NSMutableAttributedString alloc] initWithString:testString];
[setString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [testString length])]; 
// 设置Label要显示的text
[label setAttributedText:setString]; 
// 将创建的Label添加到view上
[self.view addSubview:label];
posted @ 2018-01-16 15:03  奋斗路上的奋青  阅读(1037)  评论(0编辑  收藏  举报