Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将UIWebView中的所有图像调整到一定宽度以上_Javascript_Iphone_Uiwebview_Resize - Fatal编程技术网

Javascript 将UIWebView中的所有图像调整到一定宽度以上

Javascript 将UIWebView中的所有图像调整到一定宽度以上,javascript,iphone,uiwebview,resize,Javascript,Iphone,Uiwebview,Resize,我正在开发一个iPhone应用程序,它将在webview中显示XML中的文本和图像,并将webview放置在scrollview上(每个webview都是一个页面)。有100多张不同大尺寸的图片,但我把我的webview放在550宽500高的框架上 我发现一些图像的宽度超过550,因此在滚动查看下一页(即下一个webview内容)时遇到问题 我试图为webview设置scalePageToFit,但图像和文本都显得很小 是否有人可以帮助将所有宽度超过550像素的webview图像调整为500的设

我正在开发一个iPhone应用程序,它将在webview中显示XML中的文本和图像,并将webview放置在scrollview上(每个webview都是一个页面)。有100多张不同大尺寸的图片,但我把我的webview放在550宽500高的框架上

我发现一些图像的宽度超过550,因此在滚动查看下一页(即下一个webview内容)时遇到问题

我试图为webview设置
scalePageToFit
,但图像和文本都显得很小


是否有人可以帮助将所有宽度超过550像素的webview图像调整为500的设定宽度,以便图像适合webview?在iPhone的JavaScript中或通过任何其他方式都可以做到这一点吗?

您可以尝试为正在加载到webview中的任何内容预先添加一些CSS:

use this one  
  - (UIImage*)imageWithImage:(UIImage*)image 
                  scaledToSize:(CGSize)newSize
    {
        UIGraphicsBeginImageContext(newSize);
        [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        return newImage;
    }
img {
  width: 500px;
  height: auto;
}
在Objective-C中

NSString *cssString = @"<style type='text/css'>img {width: 500px; height: auto;}</style>";
NSString *htmlString = [NSString stringWithFormat:@"%@%@",cssString,myHTMLContent];
[myWebView loadHTMLString:htmlString];
NSString*csssstring=@“img{width:500px;height:auto;}”;
NSString*htmlString=[NSString stringWithFormat:@“%@%@”,CSSSSTRING,myHTMLContent];
[myWebView加载htmlString:htmlString];

您可以尝试为正在加载到webview中的任何内容预先添加一些CSS:

img {
  width: 500px;
  height: auto;
}
在Objective-C中

NSString *cssString = @"<style type='text/css'>img {width: 500px; height: auto;}</style>";
NSString *htmlString = [NSString stringWithFormat:@"%@%@",cssString,myHTMLContent];
[myWebView loadHTMLString:htmlString];
NSString*csssstring=@“img{width:500px;height:auto;}”;
NSString*htmlString=[NSString stringWithFormat:@“%@%@”,CSSSSTRING,myHTMLContent];
[myWebView加载htmlString:htmlString];

作为NathanGaskin答案的补充,如果不想调整宽度小于500的图像的大小,可以使用“img{max width:500px;height:auto;}”。
关于最大宽度,请参见:

作为NathanGaskin答案的补充,如果不想调整宽度小于500的图像的大小,可以使用“img{max width:500px;height:auto;}”。 有关“最大宽度”,请参见: