ios - 如何以编程方式禁用 UITextField 中的复制粘贴选项

标签 ios iphone uitextfield uialertview copy-paste

我正在制作一个注册警报 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/

相关文章:

ios - 如何在 Swift 中创建自定义 UIControl 事件?

ios - 使用适用于 iOS Swift 3 的 REST API 从 AZURE 下载文件

iphone - 将 NSMutableArray 的 UIButtons 标题分配给 NSMutableArray 的 UIButtons?

iphone - 使用自定义表格单元格更改选择图像

ios - 如何使用 IBAFormSection 减小宽度?

ios - 重命名uitableview部分的标题

iphone - 比较从相机拍摄的图像与现有图像

IOS textFieldDidChange 当outlet在其他类中时

iphone - 在当前光标位置插入空格

ios - Quickblox 打开图像作为 WhatsApp