public interface UITextPasteDelegate
The location of the paste is referenced from the time the paste was initiated. If the text changes in the mean time, this might not be at the same location as before. If the old location is out of bounds of the new text, it will be clamped to the range of the current state of the text when the paste actually occurs.
The ranges passed to the 2 optional methods will reflect the actual correct range at the time of actually pasting the resulting string.
UITextView and UITextField do not have an explicit .pasteConfiguration set, but will behave like they have one set implicitly depending on a few factors:
- if the view allows editing text attributes (.allowsEditingTextAttributes == YES), it accepts items that can be read as: - plain strings - attributed strings - images (but only for UITextView) - if the view does not allow editing text attributes (.allowsEditingTextAttributes == NO), it accepts items that can be read as: - plain strings
If you modify your text control's pasteConfiguration, you should probably also use this delegate to properly handle any custom items you have there.
| Modifier and Type | Method and Description |
|---|---|
default NSAttributedString |
textPasteConfigurationSupportingCombineItemAttributedStringsForRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting,
NSArray<? extends NSAttributedString> itemStrings,
UITextRange textRange)
When you want to alter how the different item strings are combined
into one string, you can implement this method.
|
default UITextRange |
textPasteConfigurationSupportingPerformPasteOfAttributedStringToRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting,
NSAttributedString attributedString,
UITextRange textRange)
Handle the pasting of the final string.
|
default boolean |
textPasteConfigurationSupportingShouldAnimatePasteOfAttributedStringToRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting,
NSAttributedString attributedString,
UITextRange textRange)
DEPRECATED IOS13
|
default void |
textPasteConfigurationSupportingTransformPasteItem(UITextPasteConfigurationSupporting textPasteConfigurationSupporting,
UITextPasteItem item)
Will be called for each item in the paste.
|
default NSAttributedString textPasteConfigurationSupportingCombineItemAttributedStringsForRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting, NSArray<? extends NSAttributedString> itemStrings, UITextRange textRange)
default UITextRange textPasteConfigurationSupportingPerformPasteOfAttributedStringToRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting, NSAttributedString attributedString, UITextRange textRange)
default boolean textPasteConfigurationSupportingShouldAnimatePasteOfAttributedStringToRange(UITextPasteConfigurationSupporting textPasteConfigurationSupporting, NSAttributedString attributedString, UITextRange textRange)
default void textPasteConfigurationSupportingTransformPasteItem(UITextPasteConfigurationSupporting textPasteConfigurationSupporting, UITextPasteItem item)
Note: It is not required to call these result methods in the same scope as the transformPasteItem:. You can pass these on to any async handling code (see: NSItemProvider), hold on to them through a closure and/or invoke them in a completion block.
Note: You can use this UITextPasteItem on any thread, but textPasteConfigurationSupporting:transformPasteItem: will be called on the main thread.