当点击UITextField时,我们如何禁用Cut-Copy-Paste或Select-SelectAll菜单。我尝试使用下面的代码,但它没有用。
if ([UIMenuController sharedMenuController]) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
答案 0 :(得分:2)
如果是UITextView,则创建一个子类并实现此函数
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:) || action == @selector(copy:))//and put other actions also
return NO;
return [super canPerformAction:action withSender:sender];
}
答案 1 :(得分:0)
canBecomeFirstResponderhere
应该做到这一点。确保您委派了UITextField
- (BOOL)canBecomeFirstResponder {
return NO;
}