字符串属性 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 ...
随机推荐
- IOS私人API用法
先要使用class-dump 和dumpFrameworks.pl 工具 将ios的framework导出来. 下面是工具的下载地址: class-dump下载地址http://www.codethe ...
- iOS 获取联系人,并调用系统地址簿UI
1.加入 AddressBook库 推断授权状态 -(bool)checkAddressBookAuthorizationStatus { //取得授权状态 ABAuthorizationStatus ...
- Java Web整合开发(78) -- Struts 1
在Struts1.3中已经取消了<data-sources>标签,也就是说只能在1.2版中配置,因为Apache不推荐在 struts-config.xml中配置数据源.所以建议不要在st ...
- atitit.设计模式(2) -----查询方式/ command 总结
atitit.设计模式(2) -----查询方式/ command 总结 1. 应用场景: 1 1. 代替一瓦if else 1 2. 建设api rpc风格的时候儿. 1 3. 菜单是Command ...
- effective c++ 条款9 do not call virtual function in constructor or deconstructor
在构造函数中不要调用virtual函数,调用了也不会有预期的效果. 举个例子 class Transaction { public: Transaction() { log(); } ; } clas ...
- asp.net访问网络路径方法(模拟用户登录)
public class IdentityScope : IDisposable { // obtains user token [DllImport("advapi32.dll" ...
- CallContext和多线程
前一段时间正好要在某个网页程序上开一个多线程调用多个组件的尝试,这些组件是有其他团队开发的(如:印度/俄罗斯),所以修改它们的代码看起来是不太现实的,但是,令人恼火的是他们的代码中大量的用到了AppC ...
- 使用 Cordova+Visual Studio 创建跨平台移动应用(2)
目前开发移动应用有三种模式:Native.Hybird.Web,若要开发跨平台的移动应用,又希望与本地API交互,那么Hybird是一个非常好的选择. 作为一个.Net程序员,可以使用熟悉 ...
- Chrome 小工具: 启动本地应用 (Native messaging)
最近遇到一个新的问题.需要使用Chrome 插件, 从我们对我们当地的一个网站之一启动C#应用,同时通过本申请值执行不同的操作. 在这里记录下解决的过程.以便以后查找 首先我们须要新建一个google ...
- XML文件编码问题
这两天的过程中的一个项目,以解决编码格式ANSI的xml当文件.我遇到了一些问题.下面的例子现在将总结分析过程. 通过win7记事本或notepad++创建一个xml文件test_source: &l ...