iOS使用NSMutableAttributedString 实现富文本(一行文本里面不同字体大小)
2016-01-19 00:00
666 查看
摘要: iOS使用NSMutableAttributedString 实现富文本(一行文本里面不同字体大小)
常见的属性及说明
//创建一个Lable _beemer = [[UILabel alloc]initWithFrame:CGRectMake(0*RATIO, 445*RATIO, _bidBgImgView.bounds.size.width, 50*RATIO)];//初始化 _beemer.text = @"Jet";//可以无视 _beemer.textColor = [UIColor whiteColor];//设置Labe里面的字体颜色 _beemer.textAlignment = NSTextAlignmentCenter;//文字居中显示 _beemer.numberOfLines = 0;//自动换行 REGULAR_OBJ(_beemer, 20*RATIO);//宏定义设置文字字体和大小。 [_bidBgImgView addSubview:_beemer]; NSString *str = [NSString stringWithFormat:@"%@ at",_infoModels.ContactPerson];//动态获取值 //富文本 //把动态获取到的值传给富文本AttributedStr。 NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str]; //第一个参数addAttribute说明在下面有说明,第二个参数value设置改变Lable的字体和大小,第三个参数range是修改Lable文字的范围。 [AttributedStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaLTStd-Bold" size:20*RATIO] range:NSMakeRange(0, _infoModels.ContactPerson.length)]; _beemer.attributedText = AttributedStr;
常见的属性及说明
NSFontAttributeName 字体 NSParagraphStyleAttributeName 段落格式 NSForegroundColorAttributeName 字体颜色 NSBackgroundColorAttributeName 背景颜色 NSStrikethroughStyleAttributeName 删除线格式 NSUnderlineStyleAttributeName 下划线格式 NSStrokeColorAttributeName 删除线颜色 NSStrokeWidthAttributeName 删除线宽度 NSShadowAttributeName 阴影
相关文章推荐
- 基于jquery实现可定制的web在线富文本编辑器附源码下载
- 19款Javascript富文本网页编辑器
- CKEditor 整合CKFinder实现文件上传及富文本操作
- 属性字符串NSAttributedString简易教程
- NSMutableAttributedString留个记录
- 通过RTLabel、RCLabel、FTCoreText及webView结合SDWebImage等4种方式实现左滑或下拉中cell中图文混排使用场景方案
- IOS CoreText -- 基本用法
- cocos2dx-3.x: lua 富文本,文本中插入颜色文本处理
- NSAttributedString的使用
- 富文本框的使用kindeditor
- Bootstrap wysiwyg,将富文本数据保存到mysql
- iOS6之后 NSAttributedString 的福利
- Qt富文本处理
- 在ios中集成CKEditor实现富文本编辑
- 仿微信朋友圈,点击评论,生成自定义超链接,并处理
- Android(Java):在textview中显示富文本
- Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
- 富文本NSAttributedString与NSMutableAttributedString
- rails中使用富文本编辑器fckeditor
- iOS 富文本初探