因为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. APUE读书笔记-第13章-守护进程

    第13章 守护进程 13.1 引言 *守护进程也称精灵进程(daemon)是生存期较长的一种进程.它们常常在系统自举时启动,仅在系统关闭时才终止.因为它们没有控制终端,所以说它们是在后台运行的.UNI ...

  2. IOS成长之路-Nsstring搜索方法rangeOfString

    NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1该字符串 ...

  3. ubuntu12.04硬盘安装

    ubuntu12.04发布了 , 安装又是一个话题.安装系统有很多方法,比如livecd,和u盘,但这些都需借用外部设备,所以硬盘安装是最好不过的方法了.u盘,cd安装都非常的简 单,对于那些讨厌用光 ...

  4. [原创] 使用rpi + crontab + git 定时向bitbucket 推送 照片

    #前提条件,你得有一个bitbucket的帐户 1.定时启动脚本代码 使用的是crontab Cronfile 内容如下: 此文件的意思是,每隔10分钟,就运行一次 /home/pi/Rpi_uplo ...

  5. js缓冲运动

    缓冲运动 现象:逐渐变慢,最后停止 原理:距离越远,速度越大 速度的计算方式: 1,速度由距离决定 2,速度=(目标值-当前值)/缩放系数 说明:速度为正负数时,也决定了物体移动的方向 示例:div缓 ...

  6. C++ 习题 输出日期时间--友元函数

    Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函 ...

  7. CSA 第五届研讨会 想象

    参加第五届CSA云安全联盟研讨会. 人们太.所以,我们没有找到座位.立一个很长的时间.为了弥补没有时间坐在办公室.一个补回来.首先为大家介绍的信贷云,事实上独立: 信-使用-云 1. 信-使用-云 什 ...

  8. configure.ac:20: error: Autoconf version 2.65 or higher is required

    安装thrift例如,下面的问题出现: configure.ac:20: error: Autoconf version 2.65 or higher is required wget http:// ...

  9. Android client和服务器JSP互传中国

    出于兼容性简化.传统中国等多国语言.推荐使用UTF-8编码. 首选.我们期待Android到底应该怎么办: 在发送前,应该对參数值要进行UTF-8编码,我写了一个static的 转换函数.在做发送动作 ...

  10. Python 获得Facebook用户有一个共同的兴趣Friends

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: c ...