Reputation: 1408
I am using below code to convert HTML text into NSMutableAttributedString and showing it in UITextView. -
attributedStringTitle = [[NSMutableAttributedString alloc] initWithData:[titleString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
This is working fine for iOS 7 or later but not working on iOS 6.. Please help.
Upvotes: 2
Views: 386
Reputation: 15015
As per Docs NSHTMLTextDocumentType is only available on iOS 7 and later
So there are some alternatives which you can do:-
1)For this you can use a 3rd party Framework
.
2)Use UIWebView
3)Refer this display-html-text-in-uitextview
But if you only need to parse html tags into strings then you can use initWithString
api for your workaround. But before that you need to create the string object str from NSData using initWithData
:-
- (NSString *)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding;
- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attrs;
Note:- The above two api will parse html tags as a plain text
Upvotes: 1
Reputation: 7343
That is because NSHTMLTextDocumentType
is only available on iOS 7 and later. Read here for the list of available constants.
Upvotes: 1
Reputation: 112857
NSHTMLTextDocumentType
is not available in iOS6:
From the Apple docs:
NSHTMLTextDocumentType Hypertext Markup Language (HTML) document.
Available in iOS 7.0 and later.
Upvotes: 1