IOS開發調整UILabel的行間距

CGFloat heih = 20;
 
NSString * cLabelString = @"這是測試UILabel行間距的text。這是測試UILabel行間距的text。n 這是測試UILabel行間距的text。n 這是測試UILabel行間距的text。這是測試UILabel行間距的text。這是測試UILabel行間距的text。這是測試UILabel行間距的text。";
UILabel * cLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, heih, 280, 200)];
cLabel.numberOfLines = 0;
cLabel.font = [UIFont fontWithName:fontName size:16];
cLabel.textColor = [UIColor grayColor];
 
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cLabelString];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:8];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cLabelString length])];
[cLabel setAttributedText:attributedString1];
[cLabel sizeToFit];
[self.view addSubview:cLabel];
相關文章
相關標籤/搜索