How to toggle a UITextField secure text entry (hide password) in Swift?

前端 未结 24 2791
时光取名叫无心
时光取名叫无心 2021-01-30 02:00

I currently have a UITextfield with an eye icon in it that when pressed is supposed to toggle the secure text entry on and off.

I know you can che

24条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 02:55

    Use button with eye image
    and make buttonHandler method
    set Tag for button with value 1

    -(IBAction) buttonHandlerSecureText:(UIButton *)sender{
          if(sender.tag ==1){
                [self.textField setSecureTextEntry:NO];
                sender.tag = 2;
          }
          else{
                [self.textField setSecureTextEntry:YES];
                sender.tag = 1;
          }
    }
    

提交回复
热议问题