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

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];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值