0

I'm displaying an webView, and only after touching it and scrolling down the page the scroll bar appears.

How can I automatically at start,when displaying the webView set the the scroll bar so it be shown, and is it possible to control his color in objective c and not in HTML code?

1 Answer 1

0

For displaying the indicator, you can use the following trick:

  1. Implement webViewDidFinishLoad and use this method flashScrollIndicators:

    -(void)webViewDidFinishLoad:(UIWebView *)webView {
        [webView.scrollView flashScrollIndicators];
    }
    
  2. Use this category to display the indicator:

    #define noDisableVerticalScrollTag 836913
    
    @implementation UIImageView (ForScrollView)
    
    - (void) setAlpha:(float)alpha {
    
    if (self.superview.tag == noDisableVerticalScrollTag) {
        if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {
            if (self.frame.size.width < 10 && self.frame.size.height > self.frame.size.width) {
                UIScrollView *sc = (UIScrollView*)self.superview;
                if (sc.frame.size.height < sc.contentSize.height) {
                    return;
                }
            }
        }
    
        if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {
            if (self.frame.size.height < 10 && self.frame.size.height < self.frame.size.width) {
                UIScrollView *sc = (UIScrollView*)self.superview;
                if (sc.frame.size.width < sc.contentSize.width) {
                    return;
                }
            }
        }
    }
    
    [super setAlpha:alpha];
    }
    @end
    
  3. Then, give your UIWebView the tag like this:

    [webViews.scrollView setTag:noDisableVerticalScrollTag];
    

That's it, the indicator will keep in the screen after the page finish loading.

for the color issue, Do you mean to change the indicator color?

5
  • Thanks,now after first touch it's really stays visible, but at the beginning it's invisible...can I show it at start also? I used [self.webView.scrollView flashScrollIndicators]; in webViewDidFinishLoad.
    – Alex Opent
    Oct 14, 2012 at 9:14
  • it's working at the start, but after the page finish loading, try it.
    – Scar
    Oct 14, 2012 at 9:15
  • The page finish loading (small page) and only after a 'small' touch it displayed.I saw that when i changing webView with tabs without scrolling nothing happens,but after any scroll on one page the scroll bar displayed and all other pages are shown with scroll bar.
    – Alex Opent
    Oct 14, 2012 at 9:18
  • weird, I've test it on the simulator and on actual device, it's work perfectly, without touching the UIWebView the indicator appear, anyway, if you find my answer useful and helped you, don't forget to accept it and up-vote my answer.
    – Scar
    Oct 14, 2012 at 9:25
  • Its works!! but when changing webView by tabs the scroll bar size passing also and only after touching re-sizing, do you now how to re-size it or display it at top on each webView?
    – Alex Opent
    Oct 14, 2012 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.