首页 / 知识

关于 ios:如何在 UILabel 中显示替代密码字符?

2023-04-16 14:44:00

关于 ios:如何在 UILabel 中显示替代密码字符?

How do I display a substitute password character in a UILabel?

我需要显示一个包含用户帐户凭据的 UITableView。为此,我在 UITableViewCell 中使用了 UILabels。当我显示他们的密码时,我显然只想显示一个占位符密码字符而不是他们的实际密码,类似于 UITextField 设置为安全文本输入模式时。事实上,我想使用与 UITextField 相同的字符,而不是使用 \\'*\\'。

我的问题是,密码字符 UITextField 在安全模式下的字符代码是什么?


这是一种方法,例如,在原型单元格的 detailTextLabel 中显示密码"dotted out":

1
2
3
4
5
6
7
8
9
// self.password is your password string
NSMutableString *dottedPassword = [NSMutableString new];

for (int i = 0; i  [self.password length]; i++)
{
    [dottedPassword appendString:@"●"]; // BLACK CIRCLE Unicode: U+25CF, UTF-8: E2 97 8F
}

cell.detailTextLabel.text = dottedPassword;

为什么不直接使用 UITextField,使字段不可编辑并更改边框样式使其看起来像 UILabel?


在 iOS 10 中,黑圈 Unicode 字符不再与安全文本字段一致。要使用的字符是? "Z 符号点" (U 2981)。


密码字符可能是Bullets。在 Mac 上,option-8 将在您输入的任何位置插入一个。字符调色板显示它是 Unicode 2022 和 UTF8 E2 80 A2。


在 Swift 3 中你可以使用:

1
passwordLabel.text = String(password.characters.map { _ in return"?" })

虽然是一个非常古老的问题,但我遇到了同样的问题。
benzado 有正确的想法,虽然我认为 Unicode 应该是 25cf。在我看来,这正是苹果在安全 UITextField 中使用的点。


显示字符替代密码用户

最新内容

相关内容

猜你喜欢