Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent UIToolBar over UIWebView

I want to have a transparent UIToolBar over a UIWebView, so that the user gets a wider perspective and overview.

However, when I do this, you cannot see the bottom of the page. I thought about setting an offset at the bottom, but that can't be trusted, as the level of zoom may vary (and each pixel will be worth less).

How can I make the webView scroll and stop at the top edge of the UIToolBar?

like image 701
Emil Avatar asked Nov 05 '10 22:11

Emil


2 Answers

You must set the contentInset and the scrollIndicatorInsets. If you don't set the scrollIndicatorInsets, the scroll indicator will go beneath your UIToolbar which doesn't look right.

float toolbarHeight = toolbar.frame.size.height;

UIEdgeInsets insets = webView.scrollView.contentInset;
insets.bottom = toolbarHeight;
[webView.scrollView setContentInset:insets];

UIEdgeInsets indicatorInsets = webView.scrollView.scrollIndicatorInsets;
indicatorInsets.bottom = toolbarHeight;
[webView.scrollView setScrollIndicatorInsets:indicatorInsets];
like image 170
sdsykes Avatar answered Oct 13 '22 21:10

sdsykes


I fixed it by setting an inset in the UIScrollView-subview of the UIWebView:

for (id view in [webView subviews]){
    if ([view isMemberOfClass:[UIScrollView class]]){
        [(UIScrollView *)view setContentInset:UIEdgeInsetsMake(0, 0, 44, 0)];
    }
}

Looks and works great!

like image 44
Emil Avatar answered Oct 13 '22 22:10

Emil