NSAttributedString实现图文混排
来源:互联网 发布:如何成为大数据分析师 编辑:程序博客网 时间:2024/05/18 09:39
/*
常用属性
// 字体
NSFontAttributeName // UIFont, default Helvetica(Neue) 12
// 段落
NSParagraphStyleAttributeName // NSParagraphStyle, default defaultParagraphStyle
// 文字颜色
NSForegroundColorAttributeName // UIColor, default blackColor
// 背景颜色
NSBackgroundColorAttributeName // UIColor, default nil: no background
// 描边颜色
NSStrokeColorAttributeName // UIColor, default nil: same as foreground color
// 描边宽度
NSStrokeWidthAttributeName // NSNumber containing floating point value, default 0
// 阴影
NSShadowAttributeName // NSShadow, default nil: no shadow
// 附件
NSAttachmentAttributeName // NSTextAttachment, default nil
// 链接URL
NSLinkAttributeName // NSURL (preferred) or NSString
// 基线偏移量
NSBaselineOffsetAttributeName // NSNumber containing floating point value,default 0
// 下划线
NSUnderlineColorAttributeName // UIColor, default nil: same as foreground color
*/
NSString *textString =@"wdadjaisjdaowjd我的爱的哦说sado我啊啊啊http://www.baidu.com";
//初始化可变属性字符串
NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc]initWithString:textString];
//设置属性
// [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, textString.text.length)];
// [attributedString addAttribute:NSKernAttributeName value:@1 range:NSMakeRange(0, textString.text.length)];
//合并设置属性
// [attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14],NSKernAttributeName: @1} range:NSMakeRange(0, textString.text.length)];
//通过字符串获取范围
// [attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:26],NSForegroundColorAttributeName: [UIColor blueColor]} range:[textString rangeOfString:@"我的爱的哦说"]];
//获取文字并修改属性
// NSRange startRange = [textString localizedStandardRangeOfString:@"owjd"];
// NSRange endRange = [textString localizedStandardRangeOfString:@"sado"];
// [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSUnionRange(startRange, endRange)];
// 设置文本下划线
// NSRange startRange1 = [textString localizedStandardRangeOfString:@"owjd"];
// NSRange endRange1 = [textString localizedStandardRangeOfString:@"sado"];
// [attributedString addAttribute:NSUnderlineStyleAttributeName value:@1 range:NSUnionRange(startRange1, endRange1)];
// // 插入图片附件
// NSTextAttachment *imageAtta = [[NSTextAttachment alloc] init];
// imageAtta.bounds = CGRectMake(0, 0, 10, 12);
// imageAtta.image = [UIImage imageNamed:@"修改价格"];
// NSAttributedString *attach = [NSAttributedString attributedStringWithAttachment:imageAtta];
// //将图片放在最后一位
// [attributedString appendAttributedString:attach];
//// [attributedString insertAttributedString:attach atIndex:0];
//设置段落属性
// // 段落样式
// NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
// // 行间距
// [style setLineSpacing:3];
// // 段落间距
// [style setParagraphSpacing:6];
// // 首行缩进
// [style setFirstLineHeadIndent:25];
// [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(1, textString.length)];
//添加网址链接
NSRange urlRange = [textStringrangeOfString:@"http://www.baidu.com"];
[attributedString addAttribute:NSLinkAttributeNamevalue:[NSURLURLWithString:@"http://www.baidu.com"]range:NSMakeRange(urlRange.location,20)];
[attributedString addAttribute:NSBackgroundColorAttributeNamevalue:[UIColorgreenColor] range:NSMakeRange(urlRange.location,20)];
_textView.attributedText = attributedString;
- NSAttributedString实现图文混排
- NSAttributedString实现图文混排
- NSAttributedString实现图文混排
- iOS-利用NSAttributedString实现图文混排
- 图文混排之NSAttributedString
- 基于NSAttributedString与正则表达式实现的图文混排
- NSAttributedString,简单图文混排,UITextKit
- NSAttributedString的21种属性详细介绍(图文混排)
- iOS图文并排demo,图文混排,UITextView图文显示,html转NSAttributedString
- 用NSAttributedString实现简单的图文混排-----(确实几个需要注意的地方都注意到了就好了。)
- 图文混排实现
- TextKit实现图文混排
- CoreText实现图文混排
- TextKit实现图文混排
- CoreText实现图文混排
- CoreText实现图文混排
- CoreText实现图文混排
- webView实现图文混排
- 基于EasyNVR二次开发实现业务需求:直接集成EasyNVR播放页面到自身项目
- kettle安装使用 a java exception has occurred
- Android_阴影CardView
- Android Studio3.0开发JNI流程------在Android原程序基础添加自己的类的native方法
- PHP学习笔记 21
- NSAttributedString实现图文混排
- Mac布置
- 网页直播、微信直播技术解决方案:EasyNVR与EasyDSS流媒体服务器组合之区分不同场景下的easynvr
- Tensorflow Models
- 矢量图设计软件Affinity Designer win(1.6.1.93)中文破解版
- rtmp直播拉流客户端EasyRTMPClient TCP窗口大小设计方法
- Java类中 静态/实例 方法/变量
- 怎样写好一篇英文论文
- 使用代理服务器的基本常识