搜集的一些小方法
html格式 转富文本,已测过
NSAttributedString *attString = [[NSAttributedString alloc] initWithData:[string dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
此时在需要计算文字自适应高度的话
CGSize size = [attString boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-24, 30) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
富文本转字符串,未亲测
NSDictionary *tempDic = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:[NSNumber numberWithInt:NSUTF8StringEncoding]}; NSData *htmlData = [attri dataFromRange:NSMakeRange(0, attri.length) documentAttributes:tempDic error:nil];
NSString *string = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];