我只想能够向 UIWebView 的 InputAccessoryView 添加一个按钮。
有没有办法做到这一点?
您的按钮链接应如下所示:
<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;
}
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];
请告诉我这是否有效。