IOS开发-NSMutableAttributedString 富文本的使用
来源:互联网 发布:php高并发 编辑:程序博客网 时间:2024/05/01 23:29
如图标注 20元 是红色字体。
在使用attributedString 时,可以直接设置文本属性,不用创建多个label 来实现效果。
- (void)viewDidLoad { [super viewDidLoad]; [self strOne]; [self attributeStrOne]; [self attributeStrTwo]; }- (void)strOne{ NSString *str1 = @"我的信仰"; UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 320, 30)]; lab1.text = str1; [self.view addSubview:lab1];}- (void)attributeStrOne{ NSString *str2 = @"我的信仰"; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:str2]; //设置富文本样式 [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]//颜色 range:NSMakeRange(0, 1)]; [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:24.f]//大小 range:NSMakeRange(0, 2)]; UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 200, 320, 100)]; lab2.attributedText = attributedString; [self.view addSubview:lab2];}- (void)attributeStrTwo{ NSString *str3 = @"我的人生我的人生我的人生我的人生我的人生我的人生\n我的人生\n"; NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:str3]; //设置富文本 段落样式 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.lineSpacing = 10.f;//行距 style.paragraphSpacing = 20.f;//段落间距 [attributeStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, str3.length)]; UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 300, 320, 300)]; lab2.numberOfLines = 0;// 设置段落时,必须为0 lab2.attributedText = attributeStr; [self.view addSubview:lab2];}
0 0
- IOS开发-NSMutableAttributedString 富文本的使用
- 富文本的使用 NSMutableAttributedString
- 富文本的使用 NSMutableAttributedString
- ios富文本NSMutableAttributedString
- iOS使用NSMutableAttributedString实现富文本
- iOS使用NSMutableAttributedString实现富文本
- iOS使用NSMutableAttributedString 实现富文本
- IOS NSMutableAttributedString 富文本的设置
- NSMutableAttributedString IOS中的富文本
- iOS NSMutableAttributedString 实现富文本
- iOS NSMutableAttributedString 实现富文本
- iOS 富文本NSMutableAttributedString整理
- 使用NSMutableAttributedString 实现富文本
- NSMutableAttributedString富文本的实现
- NSAttributedString/NSMutableAttributedString富文本的使用(NSMutableParagraphStyle)
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- JS中(function(){xxx})(); 自执行匿名函数
- poj 2955 区间dp
- 静态链接和动态链接-----动态链接实例
- 建立eclipse+PyDev+Python+NumPy+SciPy的环境
- 光线追踪
- IOS开发-NSMutableAttributedString 富文本的使用
- Linux进程的虚拟地址空间
- VC中字符处理
- hdoj2154跳舞毯
- a+b
- GRE写作必备句型
- fragment小结
- 失控阅读笔记自然之流变
- 统计java方法(函数)的代码行数