2

In my app I am using a UIWebView for the about screen. I've made the background transparent using

webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];

But for some reason rarely (1 out of 20) the text in the UIWebView will be inivible. It's still there because the scroll bar is correct and I can also copy text out of it, but you just can't see it. If I disable the transparent background then it's fine.

Did anyone else experience this behaviour?

Update: Just disabled the transparency. It's got nothing to do with it. So actually I've got a UIWebView, where sometimes the text is invisible.

Workaround: I've found a workaround, but I don't know why it works. What I'm doing in my app is preload all UIWebViews during initialization, so that later when I bring up those views, there is no delay. I force the controller to trigger viewDidLoad by calling self.view = self.view. After that the UIWebView which is a subview in my nib is loaded and I can preload the html using

[_webView loadHTMLString:html baseURL:url];

That was my original code for loading html into my UIWebView. Now I've switched to

[_webView loadRequest:urlRequest];

and this always works. Sometimes, when I'm fast enough I can see the text pop into view when it hasn't been fully preloaded yet. With loadHTML it appears that sometimes the text also hasn't been loaded, but the pop-in step won't get executed.

So it seems that preloading with loadHTMLString sometimes can cause the text not being loaded whereas loadRequest will always succeed. Can anyone explain this behavior? I'd be curious what the difference is.

Gottfried
  • 155
  • 2
  • 11
  • `webView.opaque = NO;` - doesn't this actually make the entire view disappear? –  Mar 19 '13 at 09:09
  • No, only the background: http://stackoverflow.com/questions/3646930/how-to-make-a-transparent-uiwebview – Gottfried Mar 19 '13 at 09:16
  • I ran into this as well. Using loadRequest for all the content was not an option, so I used loadRequest for the base page, but then set its contents with document.body.innerHTML = "some content" – Saltymule Jan 23 '14 at 16:08

1 Answers1

0

In your HTML or CSS, you should explicitly define the color of your text. See below sample HTML code.

<html>
<head>
<style css="text/css">
p {color: white}
</style>
</head>
<body style="background-color: transparent;">

<h3>

<p>
 YOUR TEXT WILL GO HERE...
</p> 

</h3>
</body>
</html>
Apurv
  • 17,116
  • 8
  • 51
  • 67