ios中label富文本的设置
2016-01-21 20:07
337 查看
1.修改不同文字和颜色 //创建一个富文本 NSMutableAttributedString*attri=[[NSMutableAttributedStringalloc]initWithString:@"哈哈哈哈哈123456789"]; //修改富文本中的不同文字的样式 [attriaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor]range:NSMakeRange(0,5)]; [attriaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20]range:NSMakeRange(0,5)]; //设置数字为红色 [attriaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(5,9)]; [attriaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:30]range:NSMakeRange(5,9)]; 2,添加图片
//添加表情 NSTextAttachment*attch=[[NSTextAttachmentalloc]init]; //表情图片 attch.image=[UIImageimageNamed:@"d_aini"]; //设置图片大小 attch.bounds=CGRectMake(0,0,32,32); //创建带有图片的富文本 NSAttributedString*string=[NSAttributedStringattributedStringWithAttachment:attch]; [attriappendAttributedString:string]; //
attri是上面定义的对象
//用label的attributedText属性来使用富文本self.textLabel.attributedText=attri;
相关文章推荐
- iOS: ARC和非ARC下使用Block与循环引用问题
- StoryBoard设置Cell中的Label自适应高度
- iOS中的图形
- iOS-NSDate
- iOS AFNetworking 图片上传(修改用户头像功能)
- iOS实现图像的反色,怀旧,色彩直方图效果
- iOS开发之详解剪贴板
- iOS 忽略SIGPIPE的问题
- iOS 导航栏按钮封装
- Xcode如何删除已安装的插件
- iOS - block的简单使用
- ios中代码打开app store
- iOS 单击手势和双击手势冲突问题
- iOS安全笔记
- 线程与进程的区别和联系
- IOS常用正则表达式
- iOS开发--代码块 (得到状态栏,导航栏高度)
- iOS开发之Xcode6之后不再自动创建Pch预编译文件
- iOS block简单使用
- IOS中定时器NSTimer的开启与关闭