How to add a method to UITextField & UITextView?

后端 未结 3 748
深忆病人
深忆病人 2021-01-22 15:25

I want to put something like this in a method for UITextField & UITextView.

- (void)changeKeyboardType:(UIKeyboardType)keyboardType         


        
3条回答
  •  终归单人心
    2021-01-22 16:25

    For each of these, you can create a category.

    Interface file:

    @interface UITextField (ChangeKeyboard)
    - (void)changeKeyboardType:(UIKeyboardType)keyboardType;
    @end
    

    Implementation file:

    @implementation UITextField (ChangeKeyboard)
    - (void)changeKeyboardType:(UIKeyboardType)keyboardType {
        self.keyboardType = keyboardType;
        [self resignFirstResponder];
        [self becomeFirstResponder];
    }
    @end
    

    That would be the way to add these, but I haven't tested the functionality.

提交回复
热议问题