将按钮添加到UIWebView InputAccessoryView

时间:2013-07-05 19:57:49

标签: iphone ios objective-c uiwebview

我只想在UIWebView的InputAccessoryView中添加一个按钮。

有办法做到这一点吗?

2 个答案:

答案 0 :(得分:0)

您的按钮链接应如下所示:

<a href="button://dosomething" class="buttonStyle">Click me!</a>

我们使用的是自定义协议:button://。

现在实现这样的shouldStartLoadWithRequest:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
    // only do something if a link has been clicked...
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {     

            // check if the url requests starts with our custom protocol:
        if ([[[request URL] absoluteString] hasPrefix:@"button://"]) {
            // Do custom code
            return NO;
        } 
    }

    return YES;
}

答案 1 :(得分:-1)

    UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.items = [NSArray arrayWithObject:[[UIBarButtonItem alloc]initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(yourSelector)]];
[toolbar sizeToFit];
[self.webView.inputAccessoryView addSubview:toolbar];

请告诉我这是否有效。