Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Is it possible to hide native scrollbar in UIWebView?

I would like to hide the native scrollbar / scroller that appears when you are scrolling a UIWebView, but still keep the scrolling functionality intact. Is this possible?

Thanks in advance,

William

like image 354
pixelfreak Avatar asked May 11 '09 17:05

pixelfreak


2 Answers

It seems this question needs an updated answer:

You can directly access the scroll view associated with the web view. (read-only) in iOS 5.0 an above. I don't think developers should be supporting anything prior to iOS 5.0 unless in exceptional circumstances.

From the Apple developer docs.

@property(nonatomic, readonly, retain) UIScrollView *scrollView
Discussion
Your application can access the scroll view if it wants to customize the scrolling behavior of the web view.

Availability
Available in iOS 5.0 and later.
Declared In
UIWebView.h

Now you can directly write something like this:

webView.scrollView.showsHorizontalScrollIndicator = NO;
webView.scrollView.showsVerticalScrollIndicator = NO;

No need to go to the subviews of the webView.

like image 106
Amogh Talpallikar Avatar answered Sep 23 '22 11:09

Amogh Talpallikar


UIWebView doesn't inherit directly from UIScrollView, but you may be able to use UIScrollView properties on the UIWebView subview:

[(UIScrollView*)[webview.subviews objectAtIndex:0] setShowsHorizontalScrollIndicator:NO];
[(UIScrollView*)[webview.subviews objectAtIndex:0] setShowsVerticalScrollIndicator:NO];

No idea if this is acceptable, but it builds okay and I think it should work. Please report back if this works for you.

Also consider filing a feature request to Apple at bugreport.apple.com to add this property to a future UIWebView implementation.

like image 31
Alex Reynolds Avatar answered Sep 24 '22 11:09

Alex Reynolds