带属性的字符串 NSMutableAttributedString/NSAttributedString
来源:互联网 发布:剑网3英气军娘捏脸数据 编辑:程序博客网 时间:2024/05/15 19:17
文章转自 :http://www.2cto.com/kf/201408/323426.html
由于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上添加删除线
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];
//设置下划线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
- 带属性的字符串 NSMutableAttributedString/NSAttributedString
- UIKit 带属性的字符串 NSAttributedString、NSMutableAttributedString、NSTextStorge(未完成)
- 带属性的字符串(NSMutableAttributedString)的使用
- 带属性的字符串(NSMutableAttributedString)的使用
- 富文本带属性的字符串NSMutableAttributedString
- NSMutableAttributedString控制字符串的属性
- NSMutableAttributedString 属性字符串的使用
- NSAttributedString和NSMutableAttributedString的使用
- NSMutableAttributedString(带属性的string)
- NSMutableAttributedString && NSAttributedString
- 关于NSMutableAttributedString属性字符串的用法
- 关于NSMutableAttributedString属性字符串的用法
- iOS属性字符串NSMutableAttributedString
- iOS NSMutableAttributedString字符串属性
- 初探NSAttributedString和NSMutableAttributedString的使用
- NSAttributedString 详解(属性字符串)
- NSAttributedString字符串属性
- 1.JVM运行数据区
- Chrome DevTools(2):那些debug的技巧
- session 服务器端的存储
- ubuntu下ruby on rails环境搭建
- 【数+】我们也想啊,可我们做不到啊!
- 带属性的字符串 NSMutableAttributedString/NSAttributedString
- js浮点乘除法运算方法
- leetcode 日经贴,Cpp code -Evaluate Reverse Polish Notation
- 简述RFID系统的时隙ALOHA算法的工作过程。
- android学习之(2)----自定义View
- 第八周项目零(3):阅读程序:运算符重载
- UIImage图片处理 — 截图(capture), 缩放(scale), 设定大小(resize), 存储(save)
- 为什么前缀++/--比后缀++/--的效率高?
- 子窗体显示