//编辑类型,位移枚举
typedef NS_OPTIONS(NSUInteger, NSTextStorageEditActions) {
NSTextStorageEditedAttributes = (1 << 0),//编辑了属性
NSTextStorageEditedCharacters = (1 << 1)//编辑了字符
}
//NSTextStorage里的layoutManagers数组,NSTextStorage和layoutManagers是一对多的关系
@property(readonly, copy, NS_NONATOMIC_IOSONLY) NSArray<NSLayoutManager *> *layoutManagers;
//为NSTextStorage添加一个NSLayoutManager;
- (void)addLayoutManager:(NSLayoutManager *)aLayoutManager;
// 删除一个NSLayoutManager
- (void)removeLayoutManager:(NSLayoutManager *)aLayoutManager;
// 被修改的类型:字符或者属性或者两个都修改了
@property(readonly, NS_NONATOMIC_IOSONLY) NSTextStorageEditActions editedMask;
// 被修改的属性或者字符的范围
@property(readonly, NS_NONATOMIC_IOSONLY) NSRange editedRange;
//字符变化的长度,变长了为正数,变短了为负数
@property(readonly, NS_NONATOMIC_IOSONLY) NSInteger changeInLength;
//发出一个通知,把NSTextStorage发生的变化告诉layoutManager
- (void)edited:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta;
// 每次文本存储有修改时,这个方法都自动被调用。每次编辑后,NSTextStorage 会用这个方法来清理字符串属性,发出NSTextStorageWillProcessEditingNotification和NSTextStorageDidProcessEditingNotification通知。
- (void)processEditing;
//判断是否自动修复非法属性
@property(readonly, NS_NONATOMIC_IOSONLY) BOOL fixesAttributesLazily;
// 修复无效属性,range:要修复的范围,我测试了一下好像不调用这个字符不显示,感觉应该是这个方法存储了属性,没有这个方法就没法显示
- (void)invalidateAttributesInRange:(NSRange)range;
// 没测试出来什么用
- (void)ensureAttributesAreFixedInRange:(NSRange)range;
// 将要被修改的代理方法
//editedMask被修改的类型
//editedRange被修改的范围
//delta被修改的长度
- (void)textStorage:(NSTextStorage *)textStorage willProcessEditing:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta NS_AVAILABLE(10_11, 7_0);
// 已经被修改被修改的代理方法
//editedMask被修改的类型
//editedRange被修改的范围
//delta被修改的长度
- (void)textStorage:(NSTextStorage *)textStorage didProcessEditing:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta NS_AVAILABLE(10_11, 7_0);