【问题标题】:Add Button to UIWebView InputAccessoryView将按钮添加到 UIWebView InputAccessoryView
【发布时间】:2013-07-05 19:57:49
【问题描述】:

我只是希望能够向 UIWebView 的 InputAccessoryView 添加一个按钮。

有没有办法做到这一点?

【问题讨论】:

  • 我想保留现有按钮,但再添加一个可以激活相机条形码扫描仪的按钮。
  • 你有没有发现??这些答案不好..大多数不明白这个问题
  • @DanMoore 我最终使用了 UIToolbar。通常我会使用这个github.com/rexfinn/RFKeyboardToolbar,但我需要一种方法来保留现有的按钮,这似乎没有人理解......

标签: iphone ios objective-c uiwebview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
        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];
    

    请告诉我这是否有效。

    【讨论】:

    • 你在使用故事板吗?
    • 不,我没有使用故事板。
    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 2011-09-01
    • 2017-04-09
    • 2017-08-15
    • 2018-06-13
    • 2013-03-07
    • 2014-03-23
    • 1970-01-01
    相关资源
    最近更新 更多