/**
* 富文本转html字符串
*/
+ (NSString *)attriToStrWithAttri:(NSAttributedString *)attri{
NSDictionary *tempDic = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute:[NSNumber numberWithInt:NSUTF8StringEncoding]};
NSData *htmlData = [attri dataFromRange:NSMakeRange(0, attri.length)
documentAttributes:tempDic
error:nil];
return [[NSString alloc] initWithData:htmlData
encoding:NSUTF8StringEncoding];
}
/**
* 字符串转富文本
*/
+ (NSAttributedString *)strToAttriWithStr:(NSString *)htmlStr{
return [[NSAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding]
options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}
documentAttributes:nil
error:nil];
}
iOS 富文本转html(nsstring类型)
最新推荐文章于 2024-07-17 10:32:40 发布