Fit image of random size into a UIWebview (IOS)(将随机大小的图像放入 UIWebview (IOS))
本文介绍了将随机大小的图像放入 UIWebview (IOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将大图像放入 UIwebview 并保持图像比例与图像视图相同.
I want to fit large image into UIwebview with keeping image ratio same as image view.
我该怎么做?
我的代码如下以适合 Uiwebview 中的图像.如果图像很大,那么显示效果不好.
My code as follows to fit image in Uiwebview. if image is large then display is not good.
CGFloat screenWidth = self.view.frame.size.width;
CGFloat screenHeight = self.view.frame.size.height;
NSString *htmlString = [NSString stringWithFormat:@"%@", @"<html><head><meta name='viewport' content='user-scalable=yes,width=device-width'></head><body bgcolor='000000'><img src='%@' width='%f' height='%f' style='max-width:200% max-height:200%'></body></html>"];
imageHTML = [[NSString alloc] initWithFormat:htmlString, fileUrl, screenWidth, screenHeight];
[Webview loadHTMLString:imageHTML baseURL:nil];
[imageHTML release];
推荐答案
我用过下面的代码,效果很好.
NSString *imageHTML = [[NSString alloc] initWithFormat:@"%@%@%@", @"<!DOCTYPE html>"
"<html lang="ja">"
"<head>"
"<meta charset="UTF-8">"
"<style type="text/css">"
"html{margin:0;padding:0;}"
"body {"
"margin: 0;"
"padding: 0;"
"color: #363636;"
"font-size: 90%;"
"line-height: 1.6;"
"background: black;"
"}"
"img{"
"position: absolute;"
"top: 0;"
"bottom: 0;"
"left: 0;"
"right: 0;"
"margin: auto;"
"max-width: 100%;"
"max-height: 100%;"
"}"
"</style>"
"</head>"
"<body id="page">"
"<img src='",fileUrl,@"'/> </body></html>"];
[wview_contents loadHTMLString:imageHTML baseURL:nil];
这篇关于将随机大小的图像放入 UIWebview (IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将随机大小的图像放入 UIWebview (IOS)


基础教程推荐
猜你喜欢
- 如何使 UINavigationBar 背景透明? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01