【问题标题】:UIWebView background color with UIWebPaginationModeLeftToRight is always white带有 UIWebPaginationModeLeftToRight 的 UIWebView 背景颜色始终为白色
【发布时间】:2015-06-11 11:12:09
【问题描述】:

UIWebView 分页有问题

您可以轻松地重复它: 添加 uiwebview 作为子视图。那么

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

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

_webView.paginationMode = UIWebPaginationModeLeftToRight;

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

【问题讨论】:

标签: ios css objective-c uiwebview pagination


【解决方案1】:

如果您的网页视图无法填满整个页面,则网站的其余部分将是白色块视图。这是系统默认操作。
您可以通过将视图添加到该空间来自定义它,以使背景看起来与您的 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

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 2017-01-03
    • 2020-12-26
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多