美文网首页
4.1 NSAttributedString - 斯坦福 iOS

4.1 NSAttributedString - 斯坦福 iOS

作者: 以太死多 | 来源:发表于2016-05-16 16:53 被阅读114次

NSAttributedString/NSMutableAttributedString


  • 返回给定索引处字符的属性

      //range:返回有多少个连续的字符有相同的属性,不需要的话填写 null
      - (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)range;
    
  • 把NSAttributedString(属性字符串)转换为 NSString
    - (NSString *)string

  • 在指定范围内添加属性
    - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)aRange

  • 在指定范围内设置属性
    - (void)setAttributes:(NSDictionary<NSString *,id> *)attributes range:(NSRange)aRange

  • 在指定范围内删除属性
    - (void)removeAttribute:(NSString *)name range:(NSRange)aRange

  • 属性字典

      NSFontAttributeName: - 字体(UIFont *)
      NSParagraphStyleAttributeName: - 段落(NSParagraphStyle * / NSMutableParagraphStyle *)
      NSForegroundColorAttributeName - 前景颜色(UIColor *)
      NSBackgroundColorAttributeName:- 背景颜色(UIColor *)
      NSLigatureAttributeName;
      NSKernAttributeName;
      NSStrikethroughStyleAttributeName;
      NSUnderlineStyleAttributeName: - 下划线样式属性名(NSUnderlineStyle,结构体)
      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;

相关文章

网友评论

      本文标题:4.1 NSAttributedString - 斯坦福 iOS

      本文链接:https://www.haomeiwen.com/subject/fqvbrttx.html