ios - 在 iOS 的 UIWebview 中添加 UIButton

标签 ios objective-c button uiwebview

我想在 UIWebView 底部添加一个按钮。我浏览了几篇帖子,但没有找到任何好的答案。
谁能建议我如何实现这一目标。
我希望当用户在滚动后到达 Web View 的底部时该按钮应该在那里。 used this link also by setting the button using html but can't that button action in iOS.

我可以通过 UIWebView 上的 HTML 添加按钮。

 NSString *html = [NSString stringWithFormat:@"<html><a href='yourTag01'> <button>Indian Statistics </button> </a></html>"];
[self.webView loadHTMLString:html baseURL:nil];

该委托(delegate)在单击按钮时被调用
- (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;
}

但它不会进入 if 条件。
请帮忙!!!

最佳答案

您可以通过使用而不是这个来解决您正在做的事情:

- (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;
}

写这个:
- (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;
}

如果您喜欢尝试不同的方式,请像这样添加您的自定义 UIButton:
[webView.scrollView addSubview:btn];

然后确保 UIButton 位于 WebView 上查看的站点的末尾,使用委托(delegate)方法:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGFloat contentHeight = webView.scrollView.contentSize.height;
    [btn setFrame:CGRectMake(0, contentHeight, btn.frame.size.width, btn.frame.size.height)];
}

关于ios - 在 iOS 的 UIWebview 中添加 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20925390/

相关文章:

ios - 重用后如何使自定义 UITableViewCell 顶部单元格唯一绘制?

ios - 如何针对 CoreData 中的多个关系执行复合查询

ios - 当动画已经使用 swift 发生时,如何加速它?

objective-c - 在 cocoa 中水平切片 NSImage

ios - Swift 3,使用带有闭包的函数扩展 Objective-C 泛型类

css - 编号按钮 - 不同样式的编号和标题

ios - 在 MWPhotoBrowser 中添加一个播放按钮用于视频播放

ios - 未安装应用程序时启动 Web 应用程序

java - 如何将一个事件从一个按钮连接到另一个按钮?

javascript - Bootstrap 数据切换 ="button"不适用于 <span>