iOS/swift 프로젝트에서 아래 코드로 RTF 문서를 UITextView에로드하고 있습니다. RTF 자체에는 "blah blah [ABC.png] blah blah [DEF.png] blah ...와 같은 스타일의 텍스트가 포함되어 있습니다."UITextView에 잘로드되어 있습니다.Swift : 스타일이 지정된 RTF를로드 한 후 UITextView의 NSTextAttachment에 문자열 바꾸기
이제 [someImage.png]의 모든 항목을 실제 이미지로 NSTextAttachment로 대체하고 싶습니다. 어떻게해야합니까?
RTF 문서에 이미지를 포함시킬 수있는 가능성을 알고 있지만이 프로젝트에서는 할 수 없습니다.
if let rtfPath = Bundle.main.url(forResource: "testABC", withExtension: "rtf")
{
do
{
//load RTF to UITextView
let attributedStringWithRtf = try NSAttributedString(url: rtfPath, options: [.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)
txtView.attributedText = attributedStringWithRtf
//find all "[ABC.png]" and replace with image
let regPattern = "\\[.*?\\]"
//now...?
}
}