【发布时间】:2011-05-07 09:00:50
【问题描述】:
我想在 webView 上添加自定义按钮。当我在 url 中尝试任何内容时,它们也应该在那里。
这怎么可能??
基本上我想在 uiwebView 上放置按钮,它们是自定义按钮
//编辑的代码...
我正在这样做...这里出现了链接,但没有调用方法...您的代码中没有任何错误..:)
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *HTMLData = @"<html<a href=\"button://dosomething\" class=\"buttonStyle\">Click me!</a>--></style><br><br>";
[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
然后
- (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;
}
【问题讨论】:
-
您可以在 webview 的内容中添加 html 按钮。
-
是的,是的......我想这样做,但我该怎么做?
-
你对 html 的内容有完全的控制权吗?
-
是的,我对此有完全的控制权:)
-
nick...您的代码没有任何问题,但没有调用方法:(
标签: iphone objective-c ios uiwebview