My app allows users to format text in a UITextView by using some custom formatting buttons I've created. Now I want to enable the allowsEditingTextAttributes
property of the text view so that users can copy and paste formatted text between text views. This enables the bold/italic/underline buttons in the standard UIMenuController for the text view. This is fine, but when users change the formatting through this menu, I need to call my custom method that updates the state of my custom formatting buttons. How can I detect that a user has tapped one of the UIMenuController's formatting buttons?
I looked for notifications in the UITextView and UIMenuController class references, but didn't see anything relevant. These formatting buttons don't trigger a UITextViewTextDidChangeNotification
and don't trigger the textViewDidChange:
method of the UITextViewDelegate. I also tried subclassing the UITextView class to override a method there, but I don't know what method to override. It looks like a bold:
method doesn't exist, for example, even though a paste:
method does exist there. Does anyone know what method of what class is called when tapping one of the bold/italic/underline buttons?
These buttons aren't mentioned in the Text Programming Guide for iOS or the UIMenuController class reference, as far as I can tell.
- (void)textStorage:(NSTextStorage *)textStorage didProcessEditing:(NSTextStorageEditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta
delegate method which should be called any time changes are made to text. – Duncan Groenewald