-5

I need to scroll webview. Thats simple. But when webview is scrolled till end, I want one more view to appear as if webview and that one more view were in single scroll view. How to do that properly? Consider that its incorrect to put webview inside scrollview.

P.S. In other words, it should look like there is a webview with footer. The footer is regular android view.

Eugene Chumak
  • 3,272
  • 7
  • 34
  • 52

2 Answers2

1

A roughly method can be the following: place your UIWebView inside a UIScrollView and set the consentSize according to your needs (ie. at the end of the UIWebView contentSize append another UIView of your choice):

#import "ViewController.h"

@interface ViewController () {
    UIScrollView *aScrollView;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    aScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:aScrollView];

    UIWebView *aWebView = [[UIWebView alloc] initWithFrame:self.view.frame];
    aWebView.delegate = self;
    [aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];
    [aScrollView addSubview:aWebView];
}

- (void)webViewDidFinishLoad:(UIWebView *)webview
{
    CGFloat yourWebViewContentHeight = [[webview stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];

    [aScrollView setContentSize: CGSizeMake(aScrollView.frame.size.width, yourWebViewContentHeight + 80)];

    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, yourWebViewContentHeight, self.view.frame.size.width, 80)];
    aView.backgroundColor = [UIColor redColor];

    [aScrollView addSubview:aView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

For more fine grain you have to deal with scrollviewdelegate but this can be a good startpoint.

valvoline
  • 7,737
  • 3
  • 47
  • 52
0

Just Add Webview in Scroll View it will automatically Disable scroll of WebView, See This Demo

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/svc"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:background="@color/white">

        <WebView
            android:id="@+id/wv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none" />

        <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>

</ScrollView>
Divyang Panchal
  • 1,889
  • 1
  • 19
  • 27