iOS给UILabel设置缩进、行距、字体颜色
来源:互联网 发布:杭州雅思考试 知乎 编辑:程序博客网 时间:2024/05/22 15:18
iOS给UILabel设置缩进、行距、字体颜色
直接看代码:
牋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];
牋 /p>
//------
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"1321313123211273127318273819273817381738713712837173812731837128371297319737131719371273187328193721731793\n"];
牋 /p>
//设置字体颜色
[text addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, text.length)];
牋 /p>
//设置缩进、行距
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
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 alloc] initWithString:@"eqeqeuqoeuquequeqeqwuequeqoueqowueqoueqoshfkahfksdafhkalhfkdshf"];
//设置字体颜色
[text2 addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, text2.length)];
牋 /p>
//设置缩进、行距
NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init];
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];
- iOS给UILabel设置缩进、行距、字体颜色
- 给UIlabel设置不同字体 颜色 下划线
- iOS:设置UILabel行距实例
- iOS:设置UILabel行距实例
- iOS:UILabel设置不同字体颜色
- 根据范围给UILabel设置颜色或字体,行间距
- 设置UIlable字体的行距 字体大小 颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- iOS 设置UILabel中的text指定范围的字体颜色
- UILabel行距设置
- css设置段落缩进、行距
- 设置字体的行距和大小颜色等
- UILabel设置不同的字体颜色
- UILabel设置不同的字体颜色
- 协议和代理
- iOS ARC与MRC混编的一些解决方法
- Android双进程守护
- 蓝桥杯_算法提高_金陵十三钗(动态规划)
- 作业作业 刚才忘加Option Base 1了
- iOS给UILabel设置缩进、行距、字体颜色
- unix域socket绑定路径不创建文件问题[c语言]
- Android中横竖屏切换时,onConfigurationChanged方法不被调用
- 二维码的使用(java版)
- java中GZIPOutputStream 流的使用(EOFException)
- ColorMatrix的使用
- 整体二分 hdu5412 CRB and Queries
- Android蓝牙开发详解
- python 正则匹配电话与ip