处理textview加载html代码的时候图片的尺寸
直接把这段代码拼接上就可以了@"<head><style>img{width:100px !important;height:100px}</style></head>"
例如将图片改成宽度与textView同宽,高度为100px:
NSString *str = [NSStringstringWithFormat:@"<head><style>img{width:%f !important;height:100px}</style></head>%@",textView.width,text];
NSAttributedString *attString = [[NSAttributedStringalloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nilerror:nil];
textView.attributedText=attString;
网友评论