UIWebView PaginationMode总是显示白色背景,如何使其透明?
我尝试使用’paginationMode’为iOS 7后者制作我的html-content分页。
//set webview to transparent webView.backgroundColor = [UIColor clearColor]; webView.opaque = NO; // set multi-columns webView.paginationBreakingMode = UIWebPaginationBreakingModePage; webView.paginationMode = UIWebPaginationModeLeftToRight; webView.pageLength = webView.bounds.size.width; // set html to transparent background NSString *transparent = @"addCSSRule('html', 'background-color: transparent')"; [webView stringByEvaluatingJavaScriptFromString:transparent];
但最后网页视图总是显示白色背景,我该如何让它透明?
您可能想要提供内容背景。 但是当我们从左到右使用分页时,将webview设置为透明并提供背景颜色以查看背后的技术可能效果不佳。
我通过CSS提供内容背景解决了这个问题,并在此post的帮助下解决了html内容末尾的空白区域问题
- (void)addExtraContentView { UIWebView* wv = self.webView; if(!self.viewExtraContent) { NSString* width = [wv stringByEvaluatingJavaScriptFromString:@"document.documentElement.offsetHeight;"]; CGFloat contentHeight = [width floatValue]; CGFloat contentWidth = wv.scrollView.contentSize.width; CGFloat y = (int)contentHeight % (int)wv.frame.size.height; self.viewExtraContent = [[UIView alloc] initWithFrame:CGRectMake(contentWidth - wv.frame.size.width, y, wv.frame.size.width, (wv.frame.size.height))]; } self.viewExtraContent.backgroundColor = [BookReaderSettings shared].backgroundColor; [wv.scrollView addSubview:self.viewExtraContent]; }
当webview完成加载内容时调用此方法。
也许尝试设置scrollView的背景清除?
webView.scrollView.backgroundColor = [UIColor clearColor];
编辑好了所以看似设置后
UIWebPaginationMode
背景变成白色背后:/
在paginationmode的情况下,它不是直接从目标c代码工作。 但是,我通过为’body’标签注入CSS来完成我的工作:
NSString* path=[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]; @"addCSSRule('body', 'background-color: transparent !important; background-image:url(%@); background-repeat: repeat-x; background-size:%fpx %fpx;')",[NSURL fileURLWithPath:path],webView.frame.size.width,webView.frame.size.height];
注意:它用于UIWebPaginationModeLeftToRight ..