Color passwords (red digits, blue punctuations)
This commit is contained in:
parent
5f872e0345
commit
3e0ba8a1d5
1 changed files with 17 additions and 1 deletions
|
|
@ -33,6 +33,7 @@ class LabelTableViewCell: UITableViewCell {
|
|||
} else {
|
||||
contentLabel.text = cellData?.content
|
||||
}
|
||||
contentLabel.font = UIFont(name: "Menlo", size: contentLabel.font.pointSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +70,22 @@ class LabelTableViewCell: UITableViewCell {
|
|||
}
|
||||
|
||||
func revealPassword(_ sender: Any?) {
|
||||
contentLabel.text = cellData?.content
|
||||
if let plainPassword = cellData?.content {
|
||||
let attributePassword = NSMutableAttributedString.init(string: plainPassword)
|
||||
// draw all digits in the password into red
|
||||
// draw all punctuation characters in the password into blue
|
||||
for (index, element) in plainPassword.unicodeScalars.enumerated() {
|
||||
if NSCharacterSet.decimalDigits.contains(element) {
|
||||
attributePassword.addAttribute(NSForegroundColorAttributeName, value: UIColor.red , range: NSRange(location: index, length: 1))
|
||||
} else if NSCharacterSet.punctuationCharacters.contains(element) {
|
||||
attributePassword.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue , range: NSRange(location: index, length: 1))
|
||||
}
|
||||
}
|
||||
// set contentLabel
|
||||
contentLabel.attributedText = attributePassword
|
||||
} else {
|
||||
contentLabel.text = ""
|
||||
}
|
||||
isReveal = true
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue