答案 0 :(得分:1)
以下代码可帮助您实现所需目标:
CGRect rect=CGRectMake(0, 0, 100, 50);
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(btnDelete:)];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:CGRectMake(30, rect.origin.y+10, 130, 20) inView:yourView];
menuCont.arrowDirection = UIMenuControllerArrowUp;
menuCont.menuItems = [NSArray arrayWithObjects:menuItem,nil];
[menuCont setMenuVisible:YES animated:YES];
您还需要指定代理人。
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
BOOL retValue = NO;
if (action == @selector(paste:) )
retValue = NO ;
else if ( action == @selector(cut:) || action == @selector(copy:) )
retValue = NO;
else
retValue = [super canPerformAction:action withSender:sender];
return retValue;
}
答案 1 :(得分:0)
将警报控制器显示为弹出窗口。在警报控制器中只放一个按钮,将背景颜色设置为黑色。绝对使用这个你会得到结果。但我不知道这是正确的解决方案吗?