美文网首页
处理Textview加载HTML中的图片尺寸

处理Textview加载HTML中的图片尺寸

作者: 请不要念出我的名字 | 来源:发表于2019-08-21 14:16 被阅读0次

    处理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;

    相关文章

      网友评论

          本文标题:处理Textview加载HTML中的图片尺寸

          本文链接:https://www.haomeiwen.com/subject/ogibsctx.html