ma11hew28
ma11hew28

Reputation: 126507

How to insert NSTextAttachment into NSAttributedString?

How do I insert an NSTextAttachment at a specific location in an NSAttributedString?

Upvotes: 0

Views: 441

Answers (1)

ma11hew28
ma11hew28

Reputation: 126507

let attributedString = NSAttributedString(attachment: textAttachment)
let mutableAttributedText = NSMutableAttributedString(attributedString: textView.attributedText)
mutableAttributedText.replaceCharacters(in: selectedRange, with: attributedString)
textView.attributedText = mutableAttributedText

Upvotes: 0

Related Questions