本文介绍了如何以编程方式从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];

}


推荐答案

这篇文章有很多很好的解决方案:

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禁用复制粘贴选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:51