4.1 NSAttributedString - 斯坦福 iOS

NSAttributedString/NSMutableAttributedString


  • 返回給定索引處字符的屬性

      //range:返回有多少個連續(xù)的字符有相同的屬性,不需要的話填寫 null
      - (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)range;
    
  • 把NSAttributedString(屬性字符串)轉(zhuǎn)換為 NSString
    - (NSString *)string

  • 在指定范圍內(nèi)添加屬性
    - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)aRange

  • 在指定范圍內(nèi)設(shè)置屬性
    - (void)setAttributes:(NSDictionary<NSString *,id> *)attributes range:(NSRange)aRange

  • 在指定范圍內(nèi)刪除屬性
    - (void)removeAttribute:(NSString *)name range:(NSRange)aRange

  • 屬性字典

      NSFontAttributeName: - 字體(UIFont *)
      NSParagraphStyleAttributeName: - 段落(NSParagraphStyle * / NSMutableParagraphStyle *)
      NSForegroundColorAttributeName - 前景顏色(UIColor *)
      NSBackgroundColorAttributeName:- 背景顏色(UIColor *)
      NSLigatureAttributeName;
      NSKernAttributeName;
      NSStrikethroughStyleAttributeName;
      NSUnderlineStyleAttributeName: - 下劃線樣式屬性名(NSUnderlineStyle,結(jié)構(gòu)體)
      NSStrokeColorAttributeName: - 邊框顏色(UIColor *)
      NSStrokeWidthAttributeName: - 邊寬(NSNumber *)
      NSShadowAttributeName;
      NSTextEffectAttributeName;
      NSAttachmentAttributeName;
      NSLinkAttributeName;
      NSBaselineOffsetAttributeName;
      NSUnderlineColorAttributeName: - 下劃線顏色
      NSStrikethroughColorAttributeName;
      NSObliquenessAttributeName;
      NSExpansionAttributeName;
      NSWritingDirectionAttributeName;
      NSVerticalGlyphFormAttributeName;
    
  • 在哪兒使用 NSAttributedString ?

    • UIButton
      - (void)setAttributedTitle:(NSAttributedString *)title forState: ;

    • UILabel
      - @property (nonatomic,strong) NSAttributedString *attributedText;

    • UITextView
      - @property (nonatomic,readonly) NSTextStorage *textStorage;

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

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

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