UITextField secureTextEntry - works going from YES to NO, but changing back to YES has no effect

前端 未结 5 1802
无人及你
无人及你 2021-01-31 09:13

The above says it all- I have a UITextField set to secure, but want to give users the option to make it not secure (so they can see for sure what they typed if they are in a pri

5条回答
  •  臣服心动
    2021-01-31 10:11

    Mike R's solution is nice, but I prefer this approach:

    BOOL wasFirstResponder;
    if ((wasFirstResponder = [passwordField isFirstResponder])) {
        [passwordField resignFirstResponder];
    }
    // In this example, there is a "show password" toggle
    [passwordField setSecureTextEntry:![passwordField isSecureTextEntry]];
    if (wasFirstResponder) {
        [passwordField becomeFirstResponder];
    }
    

    That way you only becomeFirstResponder again when necessary.

提交回复
热议问题