《Objective-C 編程》16.NSAttributedString

NSFontAttributeName(字體)

UIFont, default Helvetica(Neue) 12

該屬性所對(duì)應(yīng)的值是一個(gè) UIFont 對(duì)象。該屬性用于改變一段文本的字體。

NSParagraphStyleAttributeName(段落)

NSParagraphStyle, default defaultParagraphStyle

該屬性所對(duì)應(yīng)的值是一個(gè) NSParagraphStyle 對(duì)象。該屬性在一段文本上應(yīng)用多個(gè)屬性(居中,換行模式,間距等樣式)。如果不指定該屬性,則默認(rèn)為 NSParagraphStyle 的 defaultParagraphStyle 方法返回的默認(rèn)段落屬性。

NSForegroundColorAttributeName(字體顏色)

UIColor, default blackColor

該屬性所對(duì)應(yīng)的值是一個(gè) UIColor 對(duì)象。該屬性用于指定一段文本的字體顏色。如果不指定該屬性,則默認(rèn)為黑色。

注意:
NSForegroundColorAttributeName 設(shè)置的顏色與 UILabel 的 textColor 屬性設(shè)置的顏色在地位上是相等的,與 NSBackgroundColorAttributeName 地位上也相等,誰最后賦值,最終顯示的就是誰的顏色,但是textColor屬性可以與 NSBackgroundColorAttributeName 屬性可疊加。

NSBackgroundColorAttributeName(字體背景色)

UIColor, default nil: no background

該屬性所對(duì)應(yīng)的值是一個(gè) UIColor 對(duì)象。該屬性用于指定一段文本的背景顏色。如果不指定該屬性,則默認(rèn)無背景色。

NSLigatureAttributeName(連字符)

NSNumber containing integer, default 1: default ligatures, 0: no ligatures

該屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(整數(shù))。連體字符是指某些連在一起的字符,它們采用單個(gè)的圖元符號(hào)。0 表示沒有連體字符。1 表示使用默認(rèn)的連體字符。2表示使用所有連體符號(hào)。默認(rèn)值為 1(注意,iOS 不支持值為 2)。

NSKernAttributeName(字符間距)

NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.

NSKernAttributeName 設(shè)定字符間距,取值為 NSNumber 對(duì)象(整數(shù)),正值間距加寬,負(fù)值間距變窄

NSStrikethroughStyleAttributeName(刪除線)

NSNumber containing integer, default 0: no strikethrough

NSStrikethroughStyleAttributeName 設(shè)置刪除線,取值為 NSNumber 對(duì)象(整數(shù)),枚舉常量 NSUnderlineStyle 中的值:

typedef NS_ENUM(NSInteger, NSUnderlineStyle) {
    NSUnderlineStyleNone                                    = 0x00,// 不設(shè)置刪除線
    NSUnderlineStyleSingle                                  = 0x01,// (──────)細(xì)單實(shí)線
    NSUnderlineStyleThick NS_ENUM_AVAILABLE(10_0, 7_0)      = 0x02,// (━━━━━━━)粗單實(shí)線
    NSUnderlineStyleDouble NS_ENUM_AVAILABLE(10_0, 7_0)     = 0x09,// (══════)細(xì)雙實(shí)線

    NSUnderlinePatternSolid NS_ENUM_AVAILABLE(10_0, 7_0)      = 0x0000,// (────────)
    NSUnderlinePatternDot NS_ENUM_AVAILABLE(10_0, 7_0)        = 0x0100,// (? ? ? ? ? ?)
    NSUnderlinePatternDash NS_ENUM_AVAILABLE(10_0, 7_0)       = 0x0200,// (— — — —)
    NSUnderlinePatternDashDot NS_ENUM_AVAILABLE(10_0, 7_0)    = 0x0300,// (— ? — ? — ?)
    NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0400,// (— ? ? — ? ?)

    NSUnderlineByWord NS_ENUM_AVAILABLE(10_0, 7_0)            = 0x8000// (????????????)
} NS_ENUM_AVAILABLE(10_0, 6_0);

NSUnderlineStyleAttributeName(下劃線)

NSNumber containing integer, default 0: no underline

該屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(整數(shù))。該值指定是否在文字上加上下劃線,該值參考“Underline Style Attributes”。默認(rèn)值是 NSUnderlineStyleNone。

NSStrokeColorAttributeName(文字描邊顏色)

UIColor, default nil: same as foreground color

設(shè)置文字描邊顏色,需要和NSStrokeWidthAttributeName設(shè)置描邊寬度,這樣就能使文字空心.

NSStrokeWidthAttributeName(文字描邊寬度)

NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)

NSStrokeWidthAttributeName 這個(gè)屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(小數(shù))。該值改變筆畫寬度(相對(duì)于字體 size 的百分比),負(fù)值填充效果,正值中空效果,默認(rèn)為 0,即不改變。正數(shù)只改變描邊寬度。負(fù)數(shù)同時(shí)改變文字的描邊和填充寬度。例如,對(duì)于常見的空心字,這個(gè)值通常為 3.0。
同時(shí)設(shè)置了空心的兩個(gè)屬性,并且 NSStrokeWidthAttributeName 屬性設(shè)置為整數(shù),文字前景色就無效果了。

NSShadowAttributeName(陰影)

NSShadow, default nil: no shadow

該屬性所對(duì)應(yīng)的值是一個(gè) NSShadow 對(duì)象。默認(rèn)為 nil。單獨(dú)設(shè)置不好使,和這三個(gè)任一個(gè)都好使,NSVerticalGlyphFormAttributeName,NSObliquenessAttributeNameNSExpansionAttributeName

NSTextEffectAttributeName(效果屬性)

NSString, default nil: no text effect

該屬性所對(duì)應(yīng)的值是一個(gè) NSString 對(duì)象,默認(rèn)為 nil,表示無文字效果。
NSTextEffectLetterpressStyle:圖形文字凸版印刷效果。

NSAttachmentAttributeName(附件屬性)

NSTextAttachment, default nil

NSLinkAttributeName(鏈接屬性)

NSURL (preferred) or NSString

NSBaselineOffsetAttributeName(基線偏移量)

NSNumber containing floating point value, in points; offset from baseline, default 0

NSUnderlineColorAttributeName(下劃線顏色)

UIColor, default nil: same as foreground color

NSUnderlineColorAttributeName 設(shè)置下劃線顏色,取值為 UIColor 對(duì)象,默認(rèn)值為黑色

NSStrikethroughColorAttributeName(刪除線顏色)

UIColor, default nil: same as foreground color

NSStrikethroughColorAttributeName 設(shè)置刪除線顏色,取值為 UIColor 對(duì)象,默認(rèn)值為黑色

NSObliquenessAttributeName(字體傾斜)

NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew

NSExpansionAttributeName (字體扁平化)

NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion

NSWritingDirectionAttributeName(書寫方向?qū)傩裕?/h3>

NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters. The control characters can be obtained by masking NSWritingDirection and NSWritingDirectionFormatType values. LRE: NSWritingDirectionLeftToRight|NSWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSWritingDirectionOverride,

NSVerticalGlyphFormAttributeName(橫豎排版)

An NSNumber containing an integer value. 0 means horizontal text. 1 indicates vertical text. If not specified, it could follow higher-level vertical orientation settings. Currently on iOS, it's always horizontal. The behavior for any other value is undefined.

設(shè)置文字垂直方向、水平方向顯示,該屬性所對(duì)應(yīng)的值是一個(gè) NSNumber 對(duì)象(整數(shù))。0 表示橫排文本。1 表示豎排文本。在 iOS 中,總是使用橫排文本,0 以外的值都未定義。

參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • App官方文檔 運(yùn)用 NSAttributedString 的場(chǎng)景一般有兩類 titleTextAttribute...
    JaiUnChat閱讀 3,626評(píng)論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,569評(píng)論 19 139
  • 這是我個(gè)人的學(xué)習(xí)筆記 , 如有不同見解歡迎評(píng)論交流 .( 我的微博 : http://weibo.com/John...
    JohnnyB0Y閱讀 5,911評(píng)論 4 8
  • 字符屬性 字符屬性可以應(yīng)用于 attributed string 的文本中。 NSString *const NS...
    Hevin_Chen閱讀 270評(píng)論 0 0
  • 甲:您好,您是想來了解XX產(chǎn)品的嗎? 乙:(沉默不語) 甲:看您朋友圈顯示廣州,我上周剛好去的廣州,發(fā)現(xiàn)那邊的飲食...
    零叫獸閱讀 1,455評(píng)論 0 4

友情鏈接更多精彩內(nèi)容