因为iOS7新出的NSTextStorge是NSMutableAttributedString的子类。所以要用好NSTextStorage。首先要学好NSMutableAttributedString和NSAttributedString。

按个人的理解。NSAttributedString是一个带有属性的字符串,通过该类能够灵活地操作和呈现多种样式的文字数据。

alignment //对齐方式

  firstLineHeadIndent //首行缩进

  headIndent //缩进

  tailIndent  //尾部缩进

  lineBreakMode  //断行方式

  maximumLineHeight  //最大行高

  minimumLineHeight  //最低行高

  lineSpacing  //行距

  paragraphSpacing  //段距

  paragraphSpacingBefore  //段首空间

  baseWritingDirection  //句子方向

  lineHeightMultiple  //可变行高,乘因数。

hyphenationFactor //连字符属性

NSString *const NSForegroundColorAttributeName;//值为UIColor,字体颜色,默觉得黑色。





NSString *const NSBackgroundColorAttributeName;//值为UIColor。字体背景色,默认没有。





NSString *const NSLigatureAttributeName;//值为整型NSNumber,连字属性,一般中文用不到。在英文中可能出现相邻字母连笔的情况。0为不连笔。1为默认连笔。也是默认值。2在ios 上不支持。





NSString *const NSKernAttributeName;//值为浮点数NSNumber,字距属性,默认值为0。

NSString *const NSStrikethroughStyleAttributeName;//值为整型NSNumber。可取值为





enum {





NSUnderlineStyleNone = 0×00,





NSUnderlineStyleSingle = 0×01,





};设置删除线。





NSString *const NSUnderlineStyleAttributeName;//同上。设置下划线。





NSString *const NSStrokeColorAttributeName;//值为UIColor。默认值为nil,设置的属性同ForegroundColor。





NSString *const NSStrokeWidthAttributeName;//值为浮点数NSNumber。

设置比画的粗细。





NSString *const NSShadowAttributeName;//值为NSShadow,设置比画的阴影。默认值为nil。





NSString *const NSVerticalGlyphFormAttributeName;//值为整型NSNumber,0为水平排版的字,1为垂直排版的字。

演示样例代码:

//label上加入删除线

<span style="font-family:Comic Sans MS;font-size:18px;">    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

    label.text = @"zuoyou1314";

    NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"zuoyou1314"];
[str addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt: NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)];
label.attributedText = str;
[self.window addSubview:label];</span>

//设置下划线

 NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Some String"];
[attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName value:[NSNumber numberWithInt:kCTUnderlineStyleSingle] range:(NSRange){0,[attString length]}];
self.myLabel.attributedText = attString;

版权声明:本文博主原创文章,博客,未经同意不得转载。

字符串属性 NSMutableAttributedString/NSAttributedString的更多相关文章

  1. NSAttributedString字符串属性类

    //定义一个可变字符串属性对象aStr NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithStri ...

  2. 字符串属性使用strong的原因

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  3. mysql 连接命令 表管理 ,克隆表,临时表,字符串属性,设定语句间的分隔符

    连接和断开连接mysql -h host -u user -p (即,连接的主机.用户名和使用的密码).断开输入QUIT (或\q)随时退出: 表管理克隆表注意:create table ... li ...

  4. JavaScript 常用内置对象(字符串属性、Math对象、Array数组对象)

    1.字符串属性   <script>   var test_var = "I Iove you"; console.log(test_var.charAt(3)) // ...

  5. python3 字符串属性(一)

    python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...

  6. Use a Multiline Editor for String Properties 对字符串属性使用多行编辑器

    In this lesson, you will learn how to display a multiline editor for string properties. For this pur ...

  7. NSMutableAttributedString/NSAttributedString 富文本设置

    今天在做项目的过程中,我们的设计师想要一种字体四周都带阴影的效果,但是我们平时使用的setShadowColor 和setShadowOffset是达不到这种效果,setShadowOffset 只能 ...

  8. iOS属性文字NSAttributedString

    它本身是一个Foundation框架的类, 但如果要使用它主要用到了UIKit框架中的NSAttributedString中的一些常量字符串 ----------------------------- ...

  9. javascript字符串属性及常用方法总结

    length属性:str.length; 常用方法: 1.  str.charAt(n) 查找字符串中的第n个字符,如果不在0~str.length-1之间,则返回一个空字符串 2  .str.ind ...

随机推荐

  1. template method pattern

    //DataViewer.cs using System; namespace TemplateMethodSample { abstract class DataViewer { //抽象方法:获取 ...

  2. 搬寝室 hdu

    Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆, ...

  3. 【C语言探索之旅】 第二部分第十课:练习题和习作

    内容简介 1.课程大纲 2.第二部分第十一课:  练习题和习作 3.第三部分第一课预告:  安装SDL 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言 ...

  4. swift 笔记 (十二) —— 下标

    下标 swift同意我们为 类.结构体,枚举 定义下标,以更便捷的方式訪问一大堆属性.比方Array和Dictionary都是结构体,swift的project师已经为这两个类型提供好了下标操作的代码 ...

  5. 左右canvas.drawArc,canvas.drawOval 和RectF 关联

    1.paint.setStyle(Paint.Style.STROKE) // radius="100dp" // interRadius="40dp" // ...

  6. 获取一个Jpanel的父容器有多难

    JDialog parent = (JDialog) this.getParent().getParent().getParent().getParent(); javax.swing.JPanel- ...

  7. Xcode_6.3_beta_4 官方 下载地址

    http://adcdownload.apple.com//Developer_Tools/Xcode_6.3_beta_4/Xcode_6.3_beta_4.dmg

  8. 惠普4431s 笔记本配置

    hp-4431s驱动精灵硬件检测报告 版本:2015.3.26.1363(8.1.326.1363)================================================== ...

  9. H. 硬币的水问题II

    H. 硬币水题II Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: ...

  10. 参加persist.sys物业写权限的方法

    1.于AndroidManifest.xml manifest添加属性android:sharedUserId="android.uid.system" 2.假设AndroidMa ...