如何在Swift中切换UITextField安全文本输入(隐藏密码)? [英] How to toggle a UITextField secure text entry (hide password) in Swift?

查看:280
本文介绍了如何在Swift中切换UITextField安全文本输入(隐藏密码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个带有眼睛图标的UITextfield,当按下该按钮时,可以打开和关闭安全文本输入.

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 check mark the "secure text entry" box in the attributes inspector but how to do it so it toggles whenever the icon is pressed?

推荐答案

使用此代码,

iconClick是布尔变量,或者您需要其他条件检查它,

iconClick is bool variable, or you need other condition check it,

var iconClick = true

眼睛动作方法:

@IBAction func iconAction(sender: AnyObject) {
        if(iconClick == true) {
            passwordTF.secureTextEntry = false
        } else {
            passwordTF.secureTextEntry = true
        }

        iconClick = !iconClick
    }

希望它有帮助

这篇关于如何在Swift中切换UITextField安全文本输入(隐藏密码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆