系統(tǒng)為我們提供的文本屬性
/** 系統(tǒng)提供的所有富文本屬性 */
NSFontAttributeName // 設(shè)置字體
NSParagraphStyleAttributeName // 設(shè)置段落風(fēng)格
NSForegroundColorAttributeName // 設(shè)置文字顏色
NSBackgroundColorAttributeName // 設(shè)置背景顏色
NSLigatureAttributeName // 設(shè)置連體屬性
NSKernAttributeName // 設(shè)置字符間距
NSStrikethroughStyleAttributeName // 添加刪除線
NSUnderlineStyleAttributeName // 添加下劃線
NSStrokeColorAttributeName // 設(shè)置文字描邊顏色
NSStrokeWidthAttributeName // 設(shè)置文字描邊寬度
NSShadowAttributeName // 設(shè)置陰影
NSTextEffectAttributeName // 設(shè)置文本特殊效果
NSAttachmentAttributeName // 設(shè)置文本附件
NSLinkAttributeName // 設(shè)置鏈接屬性
NSBaselineOffsetAttributeName // 設(shè)置基線偏移量
NSUnderlineColorAttributeName // 添加下劃線顏色
NSStrikethroughColorAttributeName // 添加刪除線顏色
NSObliquenessAttributeName // 設(shè)置字體傾斜
NSExpansionAttributeName // 設(shè)置文本扁平
NSWritingDirectionAttributeName // 設(shè)置文字書寫方向
NSVerticalGlyphFormAttributeName // 設(shè)置文本段落排版格式
1.NSKernAttributeName: @10 調(diào)整字句 kerning 字句調(diào)整
2.NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 設(shè)置字體
3.NSForegroundColorAttributeName :[UIColor redColor] 設(shè)置文字顏色
4.NSParagraphStyleAttributeName : paragraph 設(shè)置段落樣式
5.NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;
6.NSBackgroundColorAttributeName: [UIColor blackColor] 設(shè)置背景顏色
7.NSStrokeColorAttributeName設(shè)置文字描邊顏色,需要和NSStrokeWidthAttributeName設(shè)置描邊寬度,這樣就能使文字空心.
NSStrokeWidthAttributeName這個(gè)屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(小數(shù))。該值改變描邊寬度(相對(duì)于字體size 的百分比)。默認(rèn)為 0,即不改變。正數(shù)只改變描邊寬度。負(fù)數(shù)同時(shí)改變文字的描邊和填充寬度。例如,對(duì)于常見的空心字,這個(gè)值通常為3.0。
同時(shí)設(shè)置了空心的兩個(gè)屬性,并且NSStrokeWidthAttributeName屬性設(shè)置為整數(shù),文字前景色就無效果了
效果:
效果:
-
NSStrikethroughStyleAttributeName 添加刪除線,strikethrough刪除線
圖片.png
效果:
圖片.png -
NSUnderlineStyleAttributeName 添加下劃線
圖片.png
效果:
圖片.png - NSShadowAttributeName 設(shè)置陰影,單獨(dú)設(shè)置不好使,必須和其他屬性搭配才好使。
和這三個(gè)任一個(gè)都好使,NSVerticalGlyphFormAttributeName,NSObliquenessAttributeName,NSExpansionAttributeName
11.NSVerticalGlyphFormAttributeName
該屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(整數(shù))。0 表示橫排文本。1 表示豎排文本。在 iOS 中,總是使用橫排文本,0 以外的值都未定義。
圖片.png
效果:
圖片.png -
NSObliquenessAttributeName設(shè)置字體傾斜。Skew 斜
圖片.png
效果:
圖片.png -
NSExpansionAttributeName 設(shè)置文本扁平化
圖片.png
效果:
圖片.png