I am making a registration alertview that has a UITextField in it where the user can enter their registration number. everything is pretty much their, however I would like to remove the copy paste function from the textfield programmatically since their is no InterfaceBuilder version of the textfield I have no idea how to do this..
here Is my UIalertview thus far...
- (void)pleaseRegisterDevice {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Please Register Device!" message:@"this gets covered" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
regTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[regTextField setBackgroundColor:[UIColor whiteColor]];
regTextField.textAlignment = UITextAlignmentCenter;
[myAlertView addSubview:regTextField];
[myAlertView show];
[myAlertView release];
}
In iOS 9 we can hide the copy paste bar from keyboard
NOTE: In Swift, If you want your text field to disable all
UIResponderStandardEditActions
(cut, copy, paste, look up, share, select), use this isUITextFieldDelegate
.This post has many nice solutions: How disable Copy, Cut, Select, Select All in UITextView
My favourite is to override
canPerformAction:withSender:
:Small update of this answer for iOS 10 and earlier (Swift 3):
Storyboard users may want to look at this solution, as long as you are ok with subclassing.
I don't think that there is an easy way to achieve this through extensions or protocols.
Swift 3.1
Gist link
Swift 3.0 version