本文介绍了secureTextEntry 不会隐藏我的 UITextView 的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用点而不是实际文本来隐藏用作密码条目的 UITextView 的文本.此文本视图称为 TV_Password.为空时,文本不应隐藏,应替换为字符串密码"

I'm trying to hide the text of a UITextView, used as a password entry, using dots instead of the actual text. This text view is called TV_Password.When its empty, the text should not be hidden and should be replaced by the string "Password"

我在网上发现解决方案是将以下属性更改为 true.

I found on the net that the solution would be to change the following property to true.

self.TV_Password.secureTextEntry = true

不幸的是,这仍然没有隐藏我的文字.我将修改移到 textViewShouldBeginEditing 而不是 textViewDidBeginEditing,正如对遇到此类问题的人的建议,但它仍然不起作用.我有各种断点告诉我指令真的完成了,但什么也没发生..

Unfortunately, this still doesn't hide my text.I moved the modifications to textViewShouldBeginEditing instead of textViewDidBeginEditing, as advised to people having this kind of issue, but it still doesn't work.I haves various breakpoints telling me the instruction IS really done, but nothing happens..

有什么想法吗?

//MARK: TextViews editing

func textViewShouldBeginEditing(textView: UITextView) -> Bool {
    if (textView == self.TV_Password){
        if (self.TV_Password.text == "Password"){
            //empty text
            self.TV_Password.text = ""
            //enable secured text
            self.TV_Password.secureTextEntry = true

        }
    }
    return true
}

func textViewDidEndEditing(textView: UITextView) {
    if (textView == self.TV_Password) {
        //if password empty
        if (self.TV_Password.text == ""){
            //disable secured text
            self.TV_Password.secureTextEntry = false
            //fill with the word "Password"
            self.TV_Password.text = "Password"
        }
    }
}

推荐答案

ANSWER :UITextView 没有安全输入模式,请改用 UITextField.非常感谢!

ANSWER :UITextView doesn't have a secure entry mode, use a UITextField instead.Thanks a lot!

这篇关于secureTextEntry 不会隐藏我的 UITextView 的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:58