直接看代码:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 300, 200)];
label.numberOfLines = 0;
label.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
//------
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"1321313123211273127318273819273817381738713712837173812731837128371297319737131719371273187328193721731793\n"];
//设置字体颜色
[text addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, text.length)];
//设置缩进、行距
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.headIndent = 30;//缩进
style.firstLineHeadIndent = 0;
style.lineSpacing = 10;//行距
[text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
//------
//------
NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:@"eqeqeuqoeuquequeqeqwuequeqoueqowueqoueqoshfkahfksdafhkalhfkdshf"];
//设置字体颜色
[text2 addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, text2.length)];
//设置缩进、行距
NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init];
style2.headIndent = 0;
style2.firstLineHeadIndent = 20;
style2.lineSpacing = 5;
[text2 addAttribute:NSParagraphStyleAttributeName value:style2 range:NSMakeRange(0, text2.length)];
//------
[text appendAttributedString:text2];
label.attributedText = text;
[self.view addSubview:label];
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。