【发布时间】:2016-02-13 17:10:53
【问题描述】:
我试图隐藏用作密码输入的 UITextView 的文本,使用点而不是实际文本。此文本视图称为 TV_Password。 当其为空时,文本不应隐藏,应替换为字符串“密码”
我在网上找到解决方法是将以下属性更改为true。
self.TV_Password.secureTextEntry = true
不幸的是,这仍然没有隐藏我的文字。 我将修改移至 textViewShouldBeginEditing 而不是 textViewDidBeginEditing,正如遇到此类问题的人所建议的那样,但它仍然不起作用。 我有各种断点告诉我指令真的完成了,但什么也没发生..
有什么想法吗?
//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"
}
}
}
【问题讨论】:
-
UITextView没有安全进入模式。 -
如果你想要那个功能,你会想要使用
UITextField。 -
奇怪的是 Xcode 知道这样的方法并自动完成..即使是 UITextView.. 无论如何,非常感谢!
标签: ios swift uitextview