html和NSAttributedString相互转换
作者:
l富文本l | 来源:发表于
2017-01-12 15:56 被阅读0次- (NSString *)getHTMLWithAttributedString:(NSAttributedString *)attributedString {
NSDictionary *exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [attributedString dataFromRange:NSMakeRange(0, attributedString.length) documentAttributes:exportParams error:nil];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"pt;" withString:@"px;"];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"pt}" withString:@"px}"];
return htmlString;
}
- (NSAttributedString *)getAttributedStringWithHTML:(NSString *)htmlString{
NSData *htmltest = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *importParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attString = [[NSAttributedString alloc] initWithData:htmltest options:importParams documentAttributes:nil error:nil];
return attString;
}
本文标题:html和NSAttributedString相互转换
本文链接:https://www.haomeiwen.com/subject/daodbttx.html
网友评论