NSAttributedString文本属性设置的使用
2017-07-06 15:04
148 查看
使用NSAttributedString进行文本属性的设置。
设置字体属性,默认值:字体:Helvetica(Neue) 字号:12
NSFontAttributeName
设置文本段落排版格式,取值为 NSParagraphStyle 对象
NSParagraphStyleAttributeName
设置字体颜色,取值为 UIColor对象,默认值为黑色
NSForegroundColorAttributeName
设置字体所在区域背景颜色,取值为 UIColor对象,默认值为nil, 透明色
NSBackgroundColorAttributeName
设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符
NSLigatureAttributeName
设置字符间距,取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄
NSKernAttributeName
设置删除线,取值为 NSNumber 对象(整数)
NSStrikethroughStyleAttributeName
设置删除线颜色,取值为 UIColor 对象,默认值为黑色
NSStrikethroughColorAttributeName
设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
NSUnderlineStyleAttributeName
设置下划线颜色,取值为 UIColor 对象,默认值为黑色
NSUnderlineColorAttributeName
设置笔画宽度(粗细),取值为 NSNumber 对象(整数),负值填充效果,正值中空效果
NSStrokeWidthAttributeName
填充部分颜色,不是字体颜色,取值为 UIColor 对象
NSStrokeColorAttributeName
设置阴影属性,取值为 NSShadow 对象
NSShadowAttributeName
设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用
NSTextEffectAttributeName
设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏
NSBaselineOffsetAttributeName
设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
NSObliquenessAttributeName
设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
NSExpansionAttributeName
设置文字书写方向,从左向右书写或者从右向左书写
NSWritingDirectionAttributeName
设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
NSVerticalGlyphFormAttributeName
设置链接属性,点击后调用浏览器打开指定URL地址
NSLinkAttributeName
设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排
NSAttachmentAttributeName
设置字体属性,默认值:字体:Helvetica(Neue) 字号:12
NSFontAttributeName
NSMutableAttributedString *textFont = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体大小"]; [textFont addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:18.0] range:[@"NSAttributedString设置字体大小" rangeOfString:@"NSAttributedString"]];
设置文本段落排版格式,取值为 NSParagraphStyle 对象
NSParagraphStyleAttributeName
NSMutableParagraphStyle *rowParagraph = [[NSMutableParagraphStyle alloc] init]; rowParagraph.firstLineHeadIndent = 20; rowParagraph.lineSpacing = 10; NSMutableAttributedString *textRowSpace = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体文字间距"]; [textRowSpace addAttribute:NSParagraphStyleAttributeName value:rowParagraph range:NSMakeRange(0, textRowSpace.string.length)];
设置字体颜色,取值为 UIColor对象,默认值为黑色
NSForegroundColorAttributeName
NSMutableAttributedString *textColor = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体颜色"]; [textColor addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:[@"NSAttributedString设置字体颜色" rangeOfString:@"NSAttributedString"]];
设置字体所在区域背景颜色,取值为 UIColor对象,默认值为nil, 透明色
NSBackgroundColorAttributeName
NSMutableAttributedString *textBackColor = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体背景颜色"]; [textBackColor addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:[@"NSAttributedString设置字体背景颜色" rangeOfString:@"NSAttributedString"]];
设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符
NSLigatureAttributeName
设置字符间距,取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄
NSKernAttributeName
NSMutableAttributedString *textSizeSpace = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体文字间距"]; [textSizeSpace addAttribute:NSKernAttributeName value:@(2) range:[@"NSAttributedString设置字体文字间距" rangeOfString:@"NSAttributedString"]];
设置删除线,取值为 NSNumber 对象(整数)
NSStrikethroughStyleAttributeName
设置删除线颜色,取值为 UIColor 对象,默认值为黑色
NSStrikethroughColorAttributeName
NSMutableAttributedString *textDeleteline = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置删除线"]; [textDeleteline addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:[@"NSAttributedString设置删除线" rangeOfString:@"NSAttributedString"]]; [textDeleteline addAttribute:NSStrikethroughColorAttributeName value:[UIColor blueColor] range:[@"NSAttributedString设置删除线" rangeOfString:@"NSAttributedString"]];
设置下划线,取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似
NSUnderlineStyleAttributeName
设置下划线颜色,取值为 UIColor 对象,默认值为黑色
NSUnderlineColorAttributeName
NSMutableAttributedString *textUnderline = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置下划线"]; [textUnderline addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:[@"NSAttributedString设置下划线" rangeOfString:@"NSAttributedString"]]; [textUnderline addAttribute:NSUnderlineColorAttributeName value:[UIColor brownColor] range:[@"NSAttributedString设置下划线" rangeOfString:@"NSAttributedString"]];
设置笔画宽度(粗细),取值为 NSNumber 对象(整数),负值填充效果,正值中空效果
NSStrokeWidthAttributeName
NSMutableAttributedString *textBorderType = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体笔画样式"]; [textBorderType addAttribute:NSStrokeWidthAttributeName value:@(2) range:[@"NSAttributedString设置字体笔画样式" rangeOfString:@"NSAttributedString"]];
填充部分颜色,不是字体颜色,取值为 UIColor 对象
NSStrokeColorAttributeName
NSMutableAttributedString *textBorderColor = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体笔画颜色"]; [textBorderColor addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:[@"NSAttributedString设置字体笔画颜色" rangeOfString:@"NSAttributedString"]];
设置阴影属性,取值为 NSShadow 对象
NSShadowAttributeName
// 设置字体阴影 模糊度shadowBlurRadius 阴影颜色shadowColor 阴影偏移shadowOffset NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowBlurRadius = 1; shadow.shadowColor = [UIColor purpleColor]; shadow.shadowOffset = CGSizeMake(3, 3); // NSMutableAttributedString *textShadow = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置字体阴影"]; [textShadow addAttribute:NSShadowAttributeName value:shadow range:[@"NSAttributedString设置字体阴影" rangeOfString:@"NSAttributedString"]];
设置文本特殊效果,取值为 NSString 对象,目前只有图版印刷效果可用
NSTextEffectAttributeName
设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏
NSBaselineOffsetAttributeName
NSMutableAttributedString *textOffset = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString调整基线位置"]; [textOffset addAttribute:NSBaselineOffsetAttributeName value:@(6) range:[@"NSAttributedString调整基线位置" rangeOfString:@"NSAttributedString"]];
设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
NSObliquenessAttributeName
NSMutableAttributedString *textObliqueness = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置文本斜体"]; [textObliqueness addAttribute:NSObliquenessAttributeName value:@(0.5) range:[@"NSAttributedString设置文本斜体" rangeOfString:@"NSAttributedString"]];
设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
NSExpansionAttributeName
NSMutableAttributedString *textExpansion = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置文本压缩"]; [textExpansion addAttribute:NSExpansionAttributeName value:@(0.5) range:[@"NSAttributedString设置文本压缩" rangeOfString:@"NSAttributedString"]];
设置文字书写方向,从左向右书写或者从右向左书写
NSWritingDirectionAttributeName
设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
NSVerticalGlyphFormAttributeName
设置链接属性,点击后调用浏览器打开指定URL地址
NSLinkAttributeName
NSMutableAttributedString *textLink = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString设置超链接"]; [textLink addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.baidu.com"] range:[@"NSAttributedString设置超链接" rangeOfString:@"NSAttributedString"]];
设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排
NSAttachmentAttributeName
// 设置图文混排 // 初始化一个图文对象 NSTextAttachment *attachmentImage = [[NSTextAttachment alloc] init]; attachmentImage.image = [UIImage imageNamed:@"image"]; attachmentImage.bounds = CGRectMake(0, 0, 20.0, 20.0); NSAttributedString *attributedImage = [NSAttributedString attributedStringWithAttachment:attachmentImage]; // NSMutableAttributedString *textImage = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString图文混排"]; [textImage insertAttributedString:attributedImage atIndex:[@"NSAttributedString图文混排" rangeOfString:@"NSAttributedString"].length];
相关文章推荐
- 使用多行文本Textarea大小设置与resize属性结合使用
- TextView使用SpannableString设置某部分文本的各种属性(点击、颜色、下划线...)
- 使用属性获取文本值的集合
- 使用WMI创建站点和虚拟目录,并设置属性
- 怎么设置文本属性为只读和隐藏 C#里面采用FileSream写入一个txt文本
- C++ 使用API设置文件属性 隐藏
- 解决在ascx使用outputcache就不可以设置用户控件自己的属性
- Web用户空件的属性中自定义属性的设置和使用
- 静态属性或字段不再使用时,需要把其引用设置为null
- 怎样使用javamail的属性设置
- TortoiseSVN - 项目属性 - tsvn:logwidthmarker属性设置文本宽度指示
- 此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 ALTER AUTHORIZATION 语句将数据库所有者设置为有效登录名,然后再添加数据库关系图支持对象。
- WPF中使用Style设置界面控件外观属性
- 在配置使用Membership或其他的Providers的ASP.NET2.0时一定要设置applicationName属性
- 实现文本打印 打印机属性设置
- Dreamweaver使用CSS样式表设置网页文本格式
- 在配置使用Membership或其他的Providers的ASP.NET2.0时一定要设置applicationName属性
- 使用游标收缩数据库日志文件并调整数据库属性选项栏部分设置
- 地磅称量系统之(59) 接收串口数据(串口控件的属性设置和超级终端的使用)
- 如何使用代码动态设置水晶报表中的文本,字段等对象呢?