Sab*_*esh 4 iphone uiwebview ios
我希望将大图像放入UIwebview中,保持图像比例与图像视图相同.
我该怎么做.?
我的代码如下,以适应Uiwebview中的图像.如果图像很大,那么显示效果不佳.
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];
Run Code Online (Sandbox Code Playgroud)
Sab*_*esh 17
我使用下面的代码,它运作良好.
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];
Run Code Online (Sandbox Code Playgroud)
从UIWebView中的应用程序文档目录加载Swift 3.0中的图像与他的预期比率 -
if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let path = dir.appendingPathComponent(imageName)
let fullHTML = "<!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='\(path)'/> </body></html>"
imgWbView.loadHTMLString(fullHTML, baseURL: nil)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10949 次 |
最近记录: |