当我选择 WebView 内容时,如何删除默认菜单项,如复制、过去、全选。如何将自定义操作放在默认菜单项的中间。我把这些放在最后显示的项目,我想从头开始我的自定义操作。 我在 View didAppear 方法中使用以下代码。
UIMenuItem *customMenuItem1=[[UIMenuItem alloc] initWithTitle:@"Highlight" action:@selector(customAction1:)];
UIMenuItem *customMenuItem2=[[UIMenuItem alloc] initWithTitle:@"UnHighlight" action:@selector(UnHighlighted:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:customMenuItem1,customMenuItem2,nil]];
[UIMenuController sharedMenuController].menuVisible=YES;
请帮帮我。
最佳答案
正如这里的回答 showing custom menu on selection in UIWebView in iphone
- (void)viewDidLoad {
[super viewDidLoad];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.google.com"]]];
self.webview.backgroundColor = [UIColor blueColor];
// Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIMenuItem *customMenuItem1 = [[UIMenuItem alloc] initWithTitle:@"Custom 1" action:@selector(customAction1:)];
UIMenuItem *customMenuItem2 = [[UIMenuItem alloc] initWithTitle:@"Custom 2" action:@selector(customAction2:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:customMenuItem1, customMenuItem2, nil]];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[UIMenuController sharedMenuController] setMenuItems:nil];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (self.webview.superview != nil)// && ![urlTextField isFirstResponder])
{
if (action == @selector(customAction1:) || action == @selector(customAction2:))
{
return YES;
}
}
return [super canPerformAction:action withSender:sender];
}
-(void)customAction1:(UIMenuItem*)item
{}
-(void)customAction2:(UIMenuItem*)item
{}
关于ios - 如何从 iOS 开始显示自定义菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909897/