Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView background color

Tags:

ios

uiwebview

I am loading an HTML string into a UIWebView in order to be able to view rich text. So far, so good. But I have one small problem: in my Nib file, I set the background attribute to green. However, when it is displayed, the background is white. Then, in the class file, I added the following

[myWebView setBackgroundColor:[UIColor greenColor]];     [myWebView loadHTMLString:myString baseURL:nil]; 

However, the background is still white. I even tried reversing the order, but still comes out white background.

There is more text than the size of the UIWebView. I noticed that when I scroll down past the end of the text, the background is then green. How do I get the background for the text itself to be green?

Could you please advise me as to what I am doing wrong? Muchly appreciated.

like image 544
Namhcir Avatar asked Jul 07 '11 02:07

Namhcir


People also ask

How do I change the background color in react native Webview?

No, you cannot change the background color of a webview, but you can use another view with your background color cover on your web view.

How do I change the background color in Xcode?

At the top select the attributes inspector. Under the section "View" there should be a spot that says "Background". click that and choose your colour.

How do I change the background in Swift?

Find the view or view controller you want to change the background color of. Open it up in the interface builder and open the Attributes Inspector. Find the background color field and set it to the color you want.

How can I clear the contents of a UIWebView Wkwebview?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .


1 Answers

Set the background color in your html itself using css markup.

Or, set the webview's opaque property to NO .. and set the background of the view underneath to green.

UIWebView themselves don't seem to understand background color-- since they are rendering documents.

like image 181
Kal Avatar answered Sep 18 '22 15:09

Kal