How to disable UITextField editing but still accept touch?

后端 未结 15 2301
误落风尘
误落风尘 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:12

    Using the textfield delegate, there's a method

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    

    Return NO from this, and any attempt by the user to edit the text will be rejected.

    That way you can leave the field enabled but still prevent people pasting text into it.

提交回复
热议问题