Abhinav
Abhinav

Reputation: 38142

Disabling menu on tap of UITextField

How do we disable Cut-Copy-Paste or Select-SelectAll menu when tapped on a UITextField. I tried with below code but it did not work.

if ([UIMenuController sharedMenuController]) {
    [UIMenuController sharedMenuController].menuVisible = NO;
}

Upvotes: 0

Views: 2789

Answers (2)

Malek_Jundi
Malek_Jundi

Reputation: 6160

Make a subclass if UITextView and implement this function

- (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];
}

Upvotes: 2

HelmiB
HelmiB

Reputation: 12333

canBecomeFirstResponderhere should do the trick. make sure you delegate your UITextField

- (BOOL)canBecomeFirstResponder {
    return NO;
}

Upvotes: -2

Related Questions