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

后端 未结 6 924
醉话见心
醉话见心 2020-12-25 09:07

I have a need to display a UITableView containing a user\'s account credentials. For this, I\'m using UILabels in UITableViewCell. Whe

相关标签:
6条回答
  • 2020-12-25 09:19

    Here's a way to do this, e.g., to display the password "dotted out" in a Prototype Cell's detailTextLabel:

    // 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;
    
    0 讨论(0)
  • 2020-12-25 09:27

    The password character is probably a bullet. On a Mac, option-8 will insert one wherever you are typing. The Character Palette says it is Unicode 2022 and UTF8 E2 80 A2.

    0 讨论(0)
  • 2020-12-25 09:33

    In Swift 3 you can use:

    passwordLabel.text = String(password.characters.map { _ in return "•" })
    
    0 讨论(0)
  • 2020-12-25 09:35

    In iOS 10, the BLACK CIRCLE Unicode character is not consistent with the secure text field anymore. The character to use is ⦁ "Z NOTATION SPOT" (U+2981).

    0 讨论(0)
  • 2020-12-25 09:40

    Why not just use a UITextField, make the field non-editable and change the border style to make it look like a UILabel?

    0 讨论(0)
  • 2020-12-25 09:43

    Although a very old question, I came across the same problem. benzado has the right idee, although I think the Unicode should be 25cf. To me it looks like that's exactly the dot apple uses in a secured UITextField.

    0 讨论(0)
提交回复
热议问题