当我在某个链接上时,如何更改UIWebView
tap
操作 Controls.like ..它会打开一个带有三个选项的...我需要更改此控件,例如 ..我需要再添加一个按钮...如何做那...如何禁用它并根据我的选择添加新的...tap and hold
UIWebView
UIActionSheet
open
copy
add to reading list
UIActionsheet
UIActionSheet
代码
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *requestURL = [ request URL];
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
// Call your custom actionsheet and use the requestURL to do what you want :)
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Contextual Menu"
delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil otherButtonTitles:nil];
[sheet addButtonWithTitle:@"Save Page as Bookmark"];
[sheet addButtonWithTitle:@"Open Page in Safari"];
[sheet showInView:webView];
return NO;
}
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];
webview.delegate=self;
}
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == actionSheet.cancelButtonIndex) { return; }
switch (buttonIndex) {
case 0:
{
NSLog(@"Item A Selected");
NSLog(@"reg%@", request);
NSURL *requestURL = [request URL];
[webview loadRequest:[NSURLRequest requestWithURL:requestURL]];
break;
}
case 1:
{
NSLog(@"Item B Selected");
break;
}
}
}