字符串属性 NSMutableAttributedString/NSAttributedString
因为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的更多相关文章
- NSAttributedString字符串属性类
//定义一个可变字符串属性对象aStr NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithStri ...
- 字符串属性使用strong的原因
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- mysql 连接命令 表管理 ,克隆表,临时表,字符串属性,设定语句间的分隔符
连接和断开连接mysql -h host -u user -p (即,连接的主机.用户名和使用的密码).断开输入QUIT (或\q)随时退出: 表管理克隆表注意:create table ... li ...
- JavaScript 常用内置对象(字符串属性、Math对象、Array数组对象)
1.字符串属性 <script> var test_var = "I Iove you"; console.log(test_var.charAt(3)) // ...
- python3 字符串属性(一)
python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...
- 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 ...
- NSMutableAttributedString/NSAttributedString 富文本设置
今天在做项目的过程中,我们的设计师想要一种字体四周都带阴影的效果,但是我们平时使用的setShadowColor 和setShadowOffset是达不到这种效果,setShadowOffset 只能 ...
- iOS属性文字NSAttributedString
它本身是一个Foundation框架的类, 但如果要使用它主要用到了UIKit框架中的NSAttributedString中的一些常量字符串 ----------------------------- ...
- javascript字符串属性及常用方法总结
length属性:str.length; 常用方法: 1. str.charAt(n) 查找字符串中的第n个字符,如果不在0~str.length-1之间,则返回一个空字符串 2 .str.ind ...
随机推荐
- MySQL初步研究数据库
我用的是环境Win7.开始学习PHP和MySQL,而买了这<Head First PHP & MySQL>,从能Head First Labs官网获得HeadFirst系列书籍的相 ...
- SQL集合运算 差集 并集 交
SQL-3标准中提供了三种对检索结果进行集合运算的命令:并集UNION:交集INTERSECT:差集EXCEPT(在Oracle中叫做 MINUS).在有些数据库中对此的支持不够充分,如MySql中只 ...
- Java Swing TextArea 滚动条和获得焦点
JTextArea text=new JTextArea(); text.setLineWrap(true);//设置自己主动换行,之后则不须要设置水平滚动栏 JScrollPane scroll=n ...
- android 4.0 中出错 java.lang.UnsupportedOperationException
在android4.0中 画图的时候使用: canvas.clipPath(path, Region.Op.XOR); 报错 java.lang.UnsupportedOperationExcept ...
- 【原创】leetCodeOj --- Largest Number 解题报告
原题地址: https://oj.leetcode.com/problems/largest-number/ 题目内容: Given a list of non negative integers, ...
- char与unsigned char 差别
char 与 unsigned char的本质差别 http://bbs.csdn.net/topics/270080484 同一个内存内容:10010000 你用char* 解释是-1 ...
- android性能测试内存泄漏
1.什么是内存泄漏? 适用于该系统的内存使用内存泄漏,未回复(释放),该内存可以没有事业,也不能被其他人使用使用自己. 2.出有什么差别? 内存泄漏是分配出去的内存无法回收. 内存 ...
- 【C语言探索之旅】 第一部分第六课:条件表达式
内容简介 1.课程大纲 2.第一部分第六课:条件表达式 3.第一部分第七课预告:循环语句 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言编写三个游戏. ...
- 不用库(框架),自己写ajax
平常会使用ajax来请求数据,加载一个库(框架),或许仅仅maybe就使用了它的ajax部分. 写个ajax,一来可以经历一下处理问题的过程,提升技术能力,二来工作中有时真的用不着这么大的一个库(框架 ...
- Python计算&绘图——曲线拟合问题(转)
题目来自老师的课后作业,如下所示.很多地方应该可以直接调用函数,但是初学Python,对里面的函数还不是很了解,顺便带着学习的态度,尽量自己动手code. 测试版代码,里面带有很多注释和测试代码: # ...