Reputation: 349
I want to add to add a button at the bottom of UIWebView.I went through several posts but didn't find any good answer. Can anyone suggest me how to achieve this. I want that button should be there when the user reaches the bottom of web view after scrolling.used this link also by setting the button using html but can't that button action in iOS.
I am able to add button through HTML on UIWebView.
NSString *html = [NSString stringWithFormat:@"<html><a href='yourTag01'> <button>Indian Statistics </button> </a></html>"];
[self.webView loadHTMLString:html baseURL:nil];
This delegate is getting called on clicking the button
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL.absoluteString);
if(navigationType==UIWebViewNavigationTypeLinkClicked && [[request.URL absoluteString] isEqualToString: @"yourTag01"])
{
NSLog(@"heloo");
//your custom action code goes here
return NO;
}
return YES;
}
but it does't go in if condition. Please help!!!
Upvotes: 0
Views: 4477
Reputation: 1644
You can fix what you are doing by using instead of this:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL.absoluteString);
if(navigationType == UIWebViewNavigationTypeLinkClicked && [[request.URL absoluteString] isEqualToString: @"yourTag01"])
{
NSLog(@"heloo");
//your custom action code goes here
return NO;
}
return YES;
}
Write this:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"%@",request.URL.absoluteString);
NSRange UrlInRequestRange = [[request.URL.absoluteString lowercaseString] rangeOfString:[@"yourTag01" lowercaseString]];
if(navigationType == UIWebViewNavigationTypeLinkClicked && UrlInRequestRange.location != NSNotFound)
{
NSLog(@"heloo");
//your custom action code goes here
return NO;
}
return YES;
}
If you like trying a different way, Add your custom UIButton like this:
[webView.scrollView addSubview:btn];
Then to make sure the UIButton is at the end of the site thats viewed on your WebView use delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGFloat contentHeight = webView.scrollView.contentSize.height;
[btn setFrame:CGRectMake(0, contentHeight, btn.frame.size.width, btn.frame.size.height)];
}
Upvotes: 3