ios - load rtf file into UITextView in Swift 2 -
can me load rtf text uitextview swift 2? answers i've gotten old , out of date. text instructions on how play game i'm writing in app. far, i've been able copy , paste rtf text placeholder box. works iphones in simulator, when trying in ipad simulator or iphone 6 plus there appears double vertical scroll bars when this. looks messy.
i have real plain text of same file, can try too.
swift 3 update
if let rtfpath = bundle.main.url(forresource: "sometextfile", withextension: "rtf") { { let attributedstringwithrtf:nsattributedstring = try nsattributedstring(url: rtfpath, options: [nsdocumenttypedocumentattribute:nsrtftextdocumenttype], documentattributes: nil) self.textview.attributedtext = attributedstringwithrtf } catch let error { print("got error \(error)") } }
swift 4 update
if let rtfpath = bundle.main.url(forresource: "somertffile", withextension: "rtf") { { let attributedstringwithrtf: nsattributedstring = try nsattributedstring(url: rtfpath, options: [nsattributedstring.documentreadingoptionkey.documenttype: nsattributedstring.documenttype.rtf], documentattributes: nil) self.textview.attributedtext = attributedstringwithrtf } catch let error { print("got error \(error)") } }
Comments
Post a Comment