如何以编程方式从 UITextField 禁用复制粘贴选项 [英] How to disable copy paste option from UITextField programmatically

查看:35
本文介绍了如何以编程方式从 UITextField 禁用复制粘贴选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个注册警报视图,其中有一个 UITextField,用户可以在其中输入他们的注册号.一切都是他们的,但是我想以编程方式从文本字段中删除复制粘贴功能,因为它们不是文本字段的 InterfaceBuilder 版本我不知道该怎么做..

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..

这是我的 UIalertview 到目前为止...

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

}

推荐答案

这篇文章有很多不错的解决方案:如何在 UITextView 中禁用复制、剪切、选择、全选

This post has many nice solutions: 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];
}

这篇关于如何以编程方式从 UITextField 禁用复制粘贴选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆