如何将NSTextAttachment插入NSAttributedString?

时间:2017-04-13 14:27:31

标签: ios nsattributedstring nstextattachment

如何在NSTextAttachment

中的特定位置插入NSAttributedString

1 个答案:

答案 0 :(得分:0)

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