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?
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];
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With