在 UIWebView 中使用 Viewport 将图像缩放到宽度
我在说服远程图像使用 UIWebView 缩放到正确的大小时遇到问题。这可能是一个彻头彻尾的问题,但我做错了吗/有更好的方法吗?
我查看了 StackOverflow 上的视口示例,下面的代码似乎是正确的,但大图像仍然拉伸得比屏幕宽度更远。我希望所有图像都以相同的宽度显示(以填充屏幕),然后用户能够放大。
NSString *urlAddress = image;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//set up html
NSString *htmlString = @"<html><head><meta name=\"viewport\" content=\"width=320,user-scalable=yes,initial-scale=1.0\"></head><body><img style='width=100%' src='%@'></body></html>";
NSString *imageHTML = [[NSString alloc] initWithFormat:htmlString, url];
// Load image in UIWebView
webImageView.scalesPageToFit = YES;
[webImageView loadHTMLString:imageHTML baseURL:nil];
“图像”变量是图像在服务器上的位置。有人可以帮忙吗?
谢谢!
I'm having problems persuading my remote images to scale to the correct size using UIWebView. This is probably a total n00b question, but am I doing it wrong/is there a better way?
I've looked at Viewport examples on StackOverflow and the code below seems to be correct, but large images are still stretching further than the screen width. I'd like all images to be displayed with the same width (to fill the screen) and the user to then be able to zoom in.
NSString *urlAddress = image;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//set up html
NSString *htmlString = @"<html><head><meta name=\"viewport\" content=\"width=320,user-scalable=yes,initial-scale=1.0\"></head><body><img style='width=100%' src='%@'></body></html>";
NSString *imageHTML = [[NSString alloc] initWithFormat:htmlString, url];
// Load image in UIWebView
webImageView.scalesPageToFit = YES;
[webImageView loadHTMLString:imageHTML baseURL:nil];
The 'image' variable is the location of the image on the server. Can anyone assist?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论