您好,登錄后才能下訂單哦!
直接看代碼:
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。