0
votes

I've seen a lot of questions like this and I followed their advices but my UIWebView still has a white background. I'm using it to read some ebooks

I've set opaque property to false, I've set background color property to clear color, my webview was still white.

Opaque unchecked and Background : clear color

I've set css background-color property of all my contents to transparent and my webview is still white.

background-color: transparent;

Any idea?

1
Please share some code.casillas
Setting the backgroundColor to clearColor and setting opaque to false definitely makes the UIWebView transparent. I guess something in your CSS is overriding the transparent background color.joern
@joern I removed all the css from the content and the uiwebview background is still whiteLa masse
Could you share the HTML and CSS (with cssdesk.com or jsfiddle)?joern
I could but that would be irrelevant : When I load a simple string or even when I load nothing, the webview is still whiteLa masse

1 Answers

0
votes

Actually, the issue was these lines

wvRead.paginationBreakingMode = UIWebPaginationBreakingMode.Page
wvRead.paginationMode = UIWebPaginationMode.LeftToRight

The workaround comes from this question http://error.news/question/2188985/uiwebview-paginationmode-always-show-white-background-how-to-make-it-transparent/ :

In your CSS file, set the color you want for your body (every color work except transparent) Then, in your viewDidLoad method, write this (I'm not sure that the image is necesary though)

let transImgPath = NSBundle().pathForResource("imgtrans", ofType: "png")
wv.stringByEvaluatingJavaScriptFromString("addCSSRule('body', 'background-color: transparent !important; background-image:url(\(transImgPath)); background-repeat: repeat-x; background-size:\(wv.frame.size.width)px \(wv.frame.size.width)px;')")