How to disable UITextField editing but still accept touch?

后端 未结 15 2307
误落风尘
误落风尘 2020-11-29 19:55

I\'m making a UITextField that has a UIPickerView as inputView. Its all good, except that I can edit by copy, paste, cut and select te

15条回答
  •  温柔的废话
    2020-11-29 20:17

    This would be the simplest of all:

    in viewDidLoad:(set the delegate only for textfields which should not be editable.

    self.textfield.delegate=self;
    

    and insert this delegate function:

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return NO;
    }
    

    Thats it!

提交回复
热议问题