iOS给UILabel设置缩进、行距、字体颜色

来源:互联网 发布:杭州雅思考试 知乎 编辑:程序博客网 时间:2024/05/22 15:18

iOS给UILabel设置缩进、行距、字体颜色

2014年11月21日 移动开发 阅读 815 次

直接看代码:

UILabel *label = [[UILabel allocinitWithFrame:CGRectMake(1070300200)];

label.numberOfLines = 0;

label.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];

牋 /p>

//------

NSMutableAttributedString *text = [[NSMutableAttributedString allocinitWithString:@"1321313123211273127318273819273817381738713712837173812731837128371297319737131719371273187328193721731793\n"];

牋 /p>

//设置字体颜色

[text addAttribute:NSForegroundColorAttributeName value:[UIColor redColorrange:NSMakeRange(0, text.length)];

牋 /p>

//设置缩进、行距

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle allocinit];

style.headIndent = 30;//缩进

style.firstLineHeadIndent = 0;

style.lineSpacing = 10;//行距

[text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];

//------

牋 /p>

牋 /p>

牋 /p>

//------

NSMutableAttributedString *text2 = [[NSMutableAttributedString allocinitWithString:@"eqeqeuqoeuquequeqeqwuequeqoueqowueqoueqoshfkahfksdafhkalhfkdshf"];

//设置字体颜色

[text2 addAttribute:NSForegroundColorAttributeName value:[UIColor blueColorrange:NSMakeRange(0, text2.length)];

牋 /p>

//设置缩进、行距

NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle allocinit];

style2.headIndent = 0;

style2.firstLineHeadIndent = 20;

style2.lineSpacing = 5;

[text2 addAttribute:NSParagraphStyleAttributeName value:style2 range:NSMakeRange(0, text2.length)];

//------

牋 /p>

[text appendAttributedString:text2];

牋 /p>

label.attributedText = text;

[self.view addSubview:label];


0 0
原创粉丝点击