ios - 带有 UIWebPaginationModeLeftToRight 的 UIWebView 背景颜色始终为白色

标签 ios css objective-c uiwebview pagination

UIWebView 分页有问题

你可以很容易地重复它: 添加 uiwebview 作为 subview 。然后

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

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

_webView.paginationMode = UIWebPaginationModeLeftToRight;

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

最佳答案

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

// 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

关于ios - 带有 UIWebPaginationModeLeftToRight 的 UIWebView 背景颜色始终为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29481710/

相关文章:

asp.net - 透明div上页面中央的白色div

html - 元素在父宽度上与空间平均分布 - Angular Flexlayout 响应

ios - CAShapeLayer渲染问题

ios - 如何使动态高度 UILabel 将其他元素推开?

ios - OSX 上的 AWS MQTT

javascript - meteor / react : How to integrate react component in main template

ios - 我对 NSUserDefaults 中的 NSMutableArray 结构做错了什么? "attempt to insert non-property list object"

ios - UIModalPresentationFormSheet 的圆角

iphone - - viewDidLoad 无限循环问题...(iOS)

ios - 保存到服务器后如何在 iOS 中正确获取正确的视频方向