UIWebView背景色与UIWebPaginationModeLeftToRight总是白色的。

时间:2022-09-06 21:08:30

I have a problem with UIWebView pagination

我对UIWebView分页有问题。

you can easily repeat it: add uiwebview as a subview. then

您可以轻松地重复它:将uiwebview添加为子视图。然后

_webView.backgroundColor = [UIColor clearColor];
_webView.opaque = NO;
[_webView loadHTMLString:@"some string" baseURL:nil];

Now you have transparent background of UIWebView. But if you set

现在你有了UIWebView的透明背景。但是如果你设置

_webView.paginationMode = UIWebPaginationModeLeftToRight;

it appears with white background. Am I missing something? Why pagination mode changes background color?

它以白色背景出现。我遗漏了什么东西?为什么分页模式会改变背景颜色?

1 个解决方案

#1


0  

If your webview can't fill full page, rest of the website will be white color block view. It is system default action.
You can custom it by adding your view to that space to make the background look the same as your webview content.

如果你的webview不能填满整个页面,网站的其余部分将是白色的块视图。它是系统默认动作。您可以通过将视图添加到该空间来定制它,使背景看起来与webview内容相同。

// omit create webView and colorView
let script = "document.documentElement.offsetHeight"
let contentHeight = webView.stringByEvaluatingJavaScriptFromString(script)
let frameHeight = webView.frame.height
let lastPageHeight = frameHeight * CGFloat(webView.pageCount) - CGFloat(Double(contentHeight!)!)

colorView.backgroundColor = UIColor.blueColor()

colorView.frame = CGRectMake(webView.frame.width * CGFloat(webView.pageCount-1), webView.frame.height - lastPageHeight, webView.frame.width, lastPageHeight)

refer to https://forums.developer.apple.com/thread/27906

指的是https://forums.developer.apple.com/thread/27906

#1


0  

If your webview can't fill full page, rest of the website will be white color block view. It is system default action.
You can custom it by adding your view to that space to make the background look the same as your webview content.

如果你的webview不能填满整个页面,网站的其余部分将是白色的块视图。它是系统默认动作。您可以通过将视图添加到该空间来定制它,使背景看起来与webview内容相同。

// omit create webView and colorView
let script = "document.documentElement.offsetHeight"
let contentHeight = webView.stringByEvaluatingJavaScriptFromString(script)
let frameHeight = webView.frame.height
let lastPageHeight = frameHeight * CGFloat(webView.pageCount) - CGFloat(Double(contentHeight!)!)

colorView.backgroundColor = UIColor.blueColor()

colorView.frame = CGRectMake(webView.frame.width * CGFloat(webView.pageCount-1), webView.frame.height - lastPageHeight, webView.frame.width, lastPageHeight)

refer to https://forums.developer.apple.com/thread/27906

指的是https://forums.developer.apple.com/thread/27906