UIWebView PaginationMode always show white background, how to make it transparent?

前端 未结 3 1481
春和景丽
春和景丽 2021-02-10 14:05

I try to use \'paginationMode\' to make my html-content pagination for iOS 7 latter.

//set webview to transparent
webView.backgroundColor = [UIColor clearColor]         


        
3条回答
  •  死守一世寂寞
    2021-02-10 14:31

    Your probably want to provide content background. But the technique of setting webview transparent and providing background color to view behind this may not work well when we use pagination left to right.

    I solved this issue by providing content background through CSS and cater the issue of blank area at the end of html content with the help of this post

        - (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];
    }
    

    And call this method when webview finish loading content.

提交回复
热议问题