Date
Sep. 8th, 2024
 
2024年 8月 6日

Post: iOS: HTML 转 NSAttributedString

iOS: HTML 转 NSAttributedString

Published 12:10 Oct 20, 2014.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

将 HTML 代码转换成属性文字, 其实很简单:

- (NSAttributedString *)attributedStringFromHTML {
    NSData *data = [self dataUsingEncoding:NSUnicodeStringEncoding];
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    return attributedString;
}
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系