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;