Can NSAttributedString which contains NSTextAttachment be stored(or restored)?
At last, I used a subclass of NSKeyedArchiver named YYTextArchiver to serialize the NSAttributedString directly, and it worked for me.
Delete / Remove NSTextAttachment from UITextView
You can use replaceCharactersInRange:withString:
of NSMutableAttributedString
to remove the attachement (you got the range as parameter of the UITextViewDelegate
method):
//Retrieve the attributed string
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy];
//Remove the attachment
[mutableAttr replaceCharactersInRange:range withString:@""];
//Set the new attributed string
[textView setAttributedText:mutableAttr];
NSTextAttachment image in attributed text with foreground colour
It looks like there is a bug with the NSTextAttachment(image:)
constructor (on iOS 13, at the time of this answer), the following image attachment construction works correctly:
let attachment = NSTextAttachment()
attachment.image = image
Related Topics
Reload View When @Published Is Changed
Masked Uivisualeffectview Does Not Work on iOS 10
Get Latitude and Longitude Center of Google Map
Manage a Uipickerview from an External Class - Using Swift
How to Get the Correct Current Time in iOS
Embedding a Uitableview as a Container View Within a Uiviewcontroller
How to Store Array in Nsuserdefault in Swift
How to Rotate an Uiimageview Using Touchesmoved
Avcapturesession and Avaudiosession Recording Video While Background Music Playing Only Works Once
Creating Tableview Sections from JSON Data Swift 4
Unusernotificationcenter.Current().Getdeliverednotifications Only Ever Returns an Empty Array
Display UI (Storyboard Possibly) with Broadcast UI Extension
How to Set Clear Background in Table View Cell Swipe Action
iOS Swift Detecting Image Rotation
iOS Media Playback Controls Notification
Settitletextattributes Doesn't Work for Uitabbaritem When It Is Unselected in Swift
How to Store JSON Decodable Values into Coredata Using Swift