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;