UITextField how to disable the paste?

Solutions Collect From Internet About “UITextField how to disable the paste?”

overrides the canPerformAction:withSender: method to return NO for actions that you don’t want to allow:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        if (action == @selector(paste:))
            return NO;
        if (action == @selector(select:))   
            return NO;   
        if (action == @selector(selectAll:))   
            return NO;  
        return [super canPerformAction:action withSender:sender];
    }

In Above Code you need to write only for paste

Another way

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

Also check This link

EDITED

In iOS 7, you can do such like,,

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO];
    }];
    return [super canPerformAction:action withSender:sender];
}

For Swift User

override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(copy(_:)) || action == #selector(paste(_:)) {
        return false
    }

    return true
}