UIWebPaginationModeLeftToRight的UIWebView背景颜色始终为白色

时间:2015-04-07 00:17:18

标签: ios css objective-c uiwebview pagination

我的UIWebView分页存在问题

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

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

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

_webView.paginationMode = UIWebPaginationModeLeftToRight;

它出现白色背景。我错过了什么吗?为什么分页模式会改变背景颜色?

1 个答案:

答案 0 :(得分:0)

如果您的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)

参考https://forums.developer.apple.com/thread/27906

相关问题