如何在UIWebView中为图像制作合适的大小?

Fir*_*ist 5 html image uiwebview ios

我加载HTML到我的UIWebView那个包括TextImages.

Text适合UIWebViewImages不适合UIWebView.

它太大了UIWebView.

它显示在结尾处的滚动条UIWebView.

我想在UWebView中调整图像适合大小.所以我测试了以下代码.

self.myWebView.scalesPageToFit = YES;
Run Code Online (Sandbox Code Playgroud)

但它已修复,包括文本和文本太小,无法读取和图像是固定的.

我想正常设置文本,只想要适合大小的图像UIWeView.

我该怎么做?

aja*_*asa 10

我用css解决了这个问题.下面样式标记中包含的css将确保自动调整图像大小,保持UIWebView宽度的纵横比.希望这可以帮助!

NSString *strTemplateHTML = [NSString stringWithFormat:@"<html><head><style>img{max-width:100%%;height:auto !important;width:auto !important;};</style></head><body style='margin:0; padding:0;'>%@</body></html>", @"insert your html content here"];

[webView loadHTMLString:strTemplateHTML baseURL:nil];
Run Code Online (Sandbox Code Playgroud)


Roc*_*ker 5

使用视频元标记由iPhone/iPad上的UIWebView使用,以确定如何显示网页.

 <meta name="viewport" content="width=device-width, maximum-scale=1.0" />
Run Code Online (Sandbox Code Playgroud)

请参阅以下链接了解更多详情:

https://developer.apple.com/library/ios/DOCUMENTATION/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html