Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial black background in UIWebView on iOS7 after setting content inset

I have a problem with UIWebView on iOS7:

First I'm setting the content inset for my web view scrollview:

[webView.scrollView setContentInset:UIEdgeInsetsMake(40, 0, 0, 0)];

Then when web view loads an empty page there is a black rectangle at the bottom of the web view, that has the height 40.

It's for sure because of content inset, and I met this problem only on iOS7. How can I solve this? Any help will be appreciated!

like image 803
iOS Dev Avatar asked Jan 11 '14 13:01

iOS Dev


2 Answers

Try this code, it is not the best solution, but it will get rid the black rectangle:

[webView.scrollView setContentInset:UIEdgeInsetsMake(40, 0, -40, 0)];
like image 73
Roma Cebotari Avatar answered Oct 16 '22 12:10

Roma Cebotari


From my experience, iOS7 UIWebView does not play nice at all with custom insets and content size. It always breaks under certain conditions. We use a webview for a rich text editor, so we had to manage a volatile contentEditable="true" webview.

What we ended up doing was to take the UIWebDocumentView/UIWebBrowserView (let's call it "internal view") from the UIWebScrollView and add it as a subview in a scrollview of our own. To do this safely, we iterate the subviews of webView.scrollView and took the one whose class name has a UIWeb prefix. (You have to remember that iOS6 UIWebScrollView contains shadows as well.)

Now you have to manage your scrollview. What we did was observe changes of the frame property of the internal view and update the scrollview's contentsize accordingly.

like image 41
Léo Natan Avatar answered Oct 16 '22 13:10

Léo Natan