Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black area on UIWebView during load

Tags:

I noticed that my UITabBar gets a dark-gray color when I preform loadRequest in my UIWebView.

If I scroll my WebView during loadRequest there is a black area

enter image description here enter image description here

How can I remove this?

like image 875
Lord Vermillion Avatar asked May 19 '14 08:05

Lord Vermillion


People also ask

How can I clear the contents of a UIWebView Wkwebview?

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

Which of the following is an example of an IOS Webview?

UIWebView object is used the load and display the web content into your application, safari browser is the primary example for ios webview.


5 Answers

I've had this problem before, and it's related to the content inset of your UIWebView. This black area appears wherever you have a bottom inset set on the scrollview. I was able to fix this by setting the opaque property of the webview:

self.opaque = NO;
like image 142
michaels Avatar answered Oct 26 '22 20:10

michaels


Set for UIWebView opaque NO and clear background color simultaneously:

enter image description here

like image 20
Igor Avatar answered Oct 26 '22 19:10

Igor


You need to set the background color to clear as well as making the webView opaque. This doesn't seem to work if you don't also change the backgroundColor to clear.

self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
like image 22
Matthew Glenn Avatar answered Oct 26 '22 20:10

Matthew Glenn


I must disagree with the suggested solutions here. The recommended solution of setting the opaque and backgroudColor silently hides the real problem. If you do that, then the front-most UIWebBrowserView won't cover the entire frame with the black rectangle, and will be transparent -> but the area that was previously black will remain unused, and your content won't be displayed there.

I extracted the UIWebBrowserView and printed out its descriptions when resizing, and it seems to me that it uses rounded values for its content rectangle. As the view's frame bounds are defined as CGFloat you get rounding issues when you scale the web browser view window (resizing the wrapping view's height/width to a non-integral values).

I managed to fix this problem through rounding the setFrame arguments of my UIWebView:

UIWebView *myWebView;
....
[myWebView setFrame:CGRectMake(newX, newY, floor(newWidth), floor(newHeight)];
like image 25
SirGlorg Avatar answered Oct 26 '22 20:10

SirGlorg


In swift,

webView.opaque = false

like image 37
Jignesh Patel Avatar answered Oct 26 '22 19:10

Jignesh Patel