1.展示包含html的文字:
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.contentTextView.attributedText = attrStr;
2.计算包含html的文字的高度:
CGFloat h = [attrStr boundingRectWithSize:CGSizeMake(ScreenWidth-75-20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height + 10;
3.获取文字中链接的点击事件:
self.contentTextView.delegate = self;
代理方式:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
NSLog(@"点击链接-%@",URL);
return YES;
}
网友评论