NSTextStorage

//編輯類型,位移枚舉

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);
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容