UIWebView内容大小
我正在开发一个可以从网络检索图像的应用程序。我没有实际下载图像,而是尝试在 UIWebView 中显示它们。我确实需要图像在屏幕上具有特定的尺寸,所以我制作了一个我需要的尺寸的网络视图,并告诉它scalesPageToFit,但是当我运行时,图像在视图中的尺寸不正确。我使用 1024x768 图像作为测试,并尝试了多次迭代视图尺寸以使其在屏幕上正确显示,但最终要么得到不合逻辑的尺寸,要么出现剪辑。
这是原始图像; http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background -7.jpg
我试图将图像设置为 300 宽,这会保留纵横比,这意味着视图应该为 245 高。
第一个屏幕截图是使用 300x245 UIWebView,您可以看到宽度是正确的,但高度不正确,红色框应该与图像底部完全对齐 http://img839.imageshack.us/f/sizecropped.png/
这一秒屏幕截图的分辨率为 300x300,对于视图而言,图像缩放得太宽,也太高。 http://img155.imageshack.us/f/sizetoobig.png/
我有我已经挣扎了一段时间试图让它做我想做的事,但我只是没有取得任何成功。
编辑:我拥有的唯一相关代码是:
NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background-7.jpg"];
NSURL* url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];
[messageView.imageWebView loadRequest:urlRequest];
messageView.imageWebView.scalesPageToFit = YES;
I'm working on an app that can retrieve images from the web. Rather than actually download the images, I'm trying to display them in a UIWebView. I really need the images to be a specific size on my screen, so I have made a webview of the size I need, and told it to scalesPageToFit, but when I run, the image is not the correct size within the view. I am using a 1024x768 image as a test, and have tried numerous iterations of view sizes to get it correct on my screen, but I either end up with an illogical size, or it clips.
Here is the original image; http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background-7.jpg
I am trying to make the image 300 wide, which preserving aspect ratio, would mean the view should be 245 high.
This first screenshot is with a 300x245 UIWebView, you can see the width is correct, but the height is not, the red box should be aligned exactly with the bottom of the image
http://img839.imageshack.us/f/sizecropped.png/
This second screenshot is with a 300x300, which scales the image too wide for the view, and also too high as well.
http://img155.imageshack.us/f/sizetoobig.png/
I have been struggling for a while trying to get this to do what I want it to, but I am just not having any success whatsoever.
EDIT: The only relevant code I have is this:
NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"http://www.coolopticalillusions.com/backgrounds/freaky-desktop-background-7.jpg"];
NSURL* url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];
[messageView.imageWebView loadRequest:urlRequest];
messageView.imageWebView.scalesPageToFit = YES;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将首先使用应用程序框架作为框架创建网络视图。然后,您可以将图像添加到具有您的尺寸(300x245)的新图像视图中。将图像作为子视图添加到 web 视图中。
让我知道这是否有帮助。
I would create the webview first with the application frame as frame. Then you can add your image to a new imageview which has your size (300x245). Add the image to the webview as subview.
Let me know if that helped.