我正在制作一个注册警报 View ,其中包含一个 UITextField,用户可以在其中输入他们的注册号。一切都是他们的,但是我想以编程方式从文本字段中删除复制粘贴功能,因为它们不是文本字段的 InterfaceBuilder 版本,我不知道如何执行此操作。
这是我到目前为止的 UIalertview...
- (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];
}
最佳答案
这篇文章有很多不错的解决方案:How disable Copy, Cut, Select, Select All in UITextView
我最喜欢重写canPerformAction:withSender:
:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:))
return NO;
return [super canPerformAction:action withSender:sender];
}
关于ios - 如何以编程方式禁用 UITextField 中的复制粘贴选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701019/