NSAttributedString

富文本,一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体、字号、字体大小等各不相同的风格,可以对段落进行格式化。


字体:NSFontAttributeName  \\默认值:字体:Helvetica(Neue) 字号:12

段落样式:NSParagraphStyleAttributeName  \\设置文本段落排版格式,取值为 NSParagraphStyle

文字颜色:NSForegroundColorAttributeName  \\取值为 UIColor对象,默认值为黑色

文字背景颜色:NSBackgroundColorAttributeName \\取值为 UIColor对象,默认值为nil, 透明色

连体属性:NSLigatureAttributeName \\取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符

字符间距:NSKernAttributeName \\取值为 NSNumber 对象(整数),正值间距加宽,负值间距变窄

删除线:NSStrikethroughStyleAttributeName \\取值为 NSNumber 对象(整数)

删除线颜色:NSStrikethroughColorAttributeName \\设置删除线颜色,取值为 UIColor 对象,默认值为黑色

下划线:NSUnderlineStyleAttributeName \\取值为 NSNumber 对象(整数),枚举常量 NSUnderlineStyle中的值,与删除线类似

下划线颜色:NSUnderlineColorAttributeName \\取值为 UIColor 对象,默认值为黑色

笔画宽度:NSStrokeWidthAttributeName \\取值为 NSNumber 对象(整数),负值填充效果,正值中空效果

填充颜色:NSStrokeColorAttributeName  \\填充部分颜色,不是字体颜色,取值为 UIColor 对象

阴影:NSShadowAttributeName \\设置阴影属性,取值为 NSShadow 对象

图版印刷:NSTextEffectAttributeName \\设置文本特殊效果,取值为 NSString 对象

基线偏移:NSBaselineOffsetAttributeName \\取值为 NSNumber (float),正值上偏,负值下偏

字形倾斜度:NSObliquenessAttributeName \\取值为 NSNumber (float),正值右倾,负值左倾

字体横向拉伸:NSExpansionAttributeName \\取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本

字体书写方向:NSWritingDirectionAttributeName \\从左向右书写或者从右向左书写

排版方向:NSVerticalGlyphFormAttributeName \\取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本

链接 :NSLinkAttributeName  \\点击后打开指定URL地址

文本附件:NSAttachmentAttributeName \\取值为NSTextAttachment对象,常用于文字图片混排

/**

* API: NSParagraphStyleAttributeName

*

* 值为NSParagraphStyle,设置段落属性,默认值为[NSParagraphStyle defaultParagraphStyle]返回的值。

*

* NSMutableParagraphStyle与NSParagraphStyle包括一下属性

* alignment                ->对齐方式

* firstLineHeadIndent      ->首行缩进

* headIndent              ->缩进

* tailIndent              ->尾部缩进

* lineBreakMode            ->断行方式

* maximumLineHeight        ->最大行高

* minimumLineHeight        ->最低行高

* lineSpacing              ->行距

* paragraphSpacing        ->段距

* paragraphSpacingBefore  ->段首空间

* baseWritingDirection    ->句子方向

* lineHeightMultiple      ->可变行高,乘因数。

* hyphenationFactor        ->连字符属性

*/


部分示例代码 https://github.com/tengcoding/TTAttributedDemo

你可能感兴趣的:(NSAttributedString)