NSMutableAttributedString 的简单使用介绍
来源:互联网 发布:linux fuser 编辑:程序博客网 时间:2024/05/01 22:03
在ios开发过程中,总是会遇到一段话需要给不同的颜色以及不同字的大小,这个时候会使用到NSMutableAttributedString,以下是我自己写的一段代码,大家看看吧(复制可以直接跑).
上码:
UILabel *inLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 64, 190, 70)];
inLabel.backgroundColor = [UIColor cyanColor];
//infoLabel.backgroundColor = [UIColor clearColor];
inLabel.textAlignment = NSTextAlignmentLeft;
inLabel.font = [UIFont systemFontOfSize:13];
inLabel.numberOfLines = 0;
// infoLabel.textColor = [UIColor cyanColor];
[self.view addSubview:inLabel];
NSString *inString = @"连续签到1天得10积分;\n连续签到2天得15积分;\n连续签到3天及以上得20积分;\n注: 若连续签到终端则重新计算";
// NSString * ha = [NSString stringWithFormat:@"注:"];
// NSString * ha2 = [NSString stringWithFormat:@"1"];
// NSString * ar = [NSString stringWithFormat:@"%@,%@",ha2]
// NSRange infoRange = [infoString rangeOfString:@"注:"];
NSMutableAttributedString *inATString = [[NSMutableAttributedStringalloc]initWithString:inString ];
// [infoATString addAttribute:(NSString *)NSForegroundColorAttributeName
// value:(id)[UIColor redColor]
// range:infoRange];
[inATString addAttribute:NSForegroundColorAttributeName value:[UIColoryellowColor] range:NSMakeRange(4, 1)];
[inATString addAttribute:NSForegroundColorAttributeName value:[UIColoryellowColor] range:NSMakeRange(7,2)];
// NSRange range = NSMakeRange(infoString.length-1, 1);
//[infoATString addAttribute:(NSString *)kCTFontAttributeName value:(id)[UIFont systemFontOfSize:10] range:range];
[inLabel setAttributedText:inATString];
- NSMutableAttributedString 的简单使用介绍
- 关于NSMutableAttributedString 的使用以及介绍
- NSMutableAttributedString使用介绍
- NSMutableAttributedString使用介绍
- NSMutableAttributedString简单使用
- NSMutableAttributedString的使用
- NSMutableAttributedString 的使用
- 【swift】NSMutableAttributedString的使用
- NSMutableAttributedString 属性字符串的使用
- 富文本的使用 NSMutableAttributedString
- NSAttributedString和NSMutableAttributedString的使用
- 富文本的使用 NSMutableAttributedString
- NSMutableAttributedString 使用
- NSMutableAttributedString使用
- NSMutableAttributedString使用
- NSMutableAttributedString使用
- 带属性的字符串(NSMutableAttributedString)的使用
- 带属性的字符串(NSMutableAttributedString)的使用
- python try/except/finally
- bitnami 版 gitlab 修改端口
- MFC下MD5加密算法实现,带key(32位MD5小写)
- WebService的创建,部署和使用
- c++中static的用法总结
- NSMutableAttributedString 的简单使用介绍
- w3c学习php笔记(一)
- 【python】错误 调试 测试try except finally raise
- android教学 listview再讲解
- Node.js回调黑洞全解
- 算法训练 矩阵乘法
- 设计模式——适配器模式和外观模式
- java中的String
- web--p 缩进 text-indent text-decoration 下划线