Reputation: 7577
I have a file with text that should be displayed in a UITextView. I would like to add support of formatting of this text like bold.
Is it possible to define these formatting options in the file and load it into a NSAttributedString? All examples I have found so far, sets a specific range of the string to e.g. bold, but I would like to preserve this formatting options in the file on disk.
On other words Is it possible to write some mark down kind of text in the file and load it directly into a UITextView while preserving text formatting.
Upvotes: 2
Views: 56
Reputation: 257663
Enclose all text in file content in HTML <b></b>
tag and load it in NSAttributedString
using some initWithHTML:
initializer, like
- (nullable instancetype)initWithHTML:(NSData *)data documentAttributes:(NSDictionary<NSAttributedStringDocumentAttributeKey, id> * _Nullable * _Nullable)dict;
Upvotes: 1