I have a UITextView where I\'m managing an NSAttributedString, initially entered as normal via the keyboard. I save the attributed string as HTML, which looks fine. When I
Using and css works for me, following Parsing HTML into NSAttributedText - how to set font?:
// HTML -> NSAttributedString
+ (NSAttributedString *)attributedStringFromHTML:(NSString *)html {
NSError *error;
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:&error];
if(!attrString) {
NSLog(@"creating attributed string from HTML failed: %@", error.debugDescription);
}
return attrString;
}
// force font thrugh & css
+ (NSAttributedString *)attributedStringFromHTML:(NSString *)html withFont:(UIFont *)font {
return [Util attributedStringFromHTML:[NSString stringWithFormat:@"%@", font.fontName, font.pointSize, html]];
}
This sets the font name and size but doesn't impact the styles.