show password as dots by default, and "reveal" and "conceal" menu
This commit is contained in:
parent
a7bd92c61f
commit
ea6bc0a7bd
2 changed files with 29 additions and 1 deletions
|
|
@ -19,11 +19,18 @@ class LabelTableViewCell: UITableViewCell {
|
||||||
@IBOutlet weak var contentLabel: UILabel!
|
@IBOutlet weak var contentLabel: UILabel!
|
||||||
@IBOutlet weak var titleLabel: UILabel!
|
@IBOutlet weak var titleLabel: UILabel!
|
||||||
|
|
||||||
|
var isPasswordCell = false
|
||||||
|
var isReveal = false
|
||||||
|
let passwordDots = "••••••••••••"
|
||||||
|
|
||||||
var cellData: LabelTableViewCellData? {
|
var cellData: LabelTableViewCellData? {
|
||||||
didSet {
|
didSet {
|
||||||
titleLabel.text = cellData?.title
|
titleLabel.text = cellData?.title
|
||||||
contentLabel.text = cellData?.content
|
if isPasswordCell {
|
||||||
|
contentLabel.text = passwordDots
|
||||||
|
} else {
|
||||||
|
contentLabel.text = cellData?.content
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,10 +49,27 @@ class LabelTableViewCell: UITableViewCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||||
|
if isPasswordCell {
|
||||||
|
if isReveal {
|
||||||
|
return action == #selector(copy(_:)) || action == #selector(LabelTableViewCell.concealPassword(_:))
|
||||||
|
} else {
|
||||||
|
return action == #selector(copy(_:)) || action == #selector(LabelTableViewCell.revealPassword(_:))
|
||||||
|
}
|
||||||
|
}
|
||||||
return action == #selector(copy(_:))
|
return action == #selector(copy(_:))
|
||||||
}
|
}
|
||||||
|
|
||||||
override func copy(_ sender: Any?) {
|
override func copy(_ sender: Any?) {
|
||||||
UIPasteboard.general.string = contentLabel.text
|
UIPasteboard.general.string = contentLabel.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func revealPassword(_ sender: Any?) {
|
||||||
|
contentLabel.text = cellData?.content
|
||||||
|
isReveal = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func concealPassword(_ sender: Any?) {
|
||||||
|
contentLabel.text = passwordDots
|
||||||
|
isReveal = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,9 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
if let tappedCell = self.tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell {
|
if let tappedCell = self.tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell {
|
||||||
tappedCell.becomeFirstResponder()
|
tappedCell.becomeFirstResponder()
|
||||||
let menuController = UIMenuController.shared
|
let menuController = UIMenuController.shared
|
||||||
|
let revealItem = UIMenuItem(title: "Reveal", action: #selector(LabelTableViewCell.revealPassword(_:)))
|
||||||
|
let concealItem = UIMenuItem(title: "Conceal", action: #selector(LabelTableViewCell.concealPassword(_:)))
|
||||||
|
menuController.menuItems = [revealItem, concealItem]
|
||||||
menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!)
|
menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!)
|
||||||
menuController.setMenuVisible(true, animated: true)
|
menuController.setMenuVisible(true, animated: true)
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +82,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
|
|
||||||
let titleData = tableData[indexPath.section].item[indexPath.row].title
|
let titleData = tableData[indexPath.section].item[indexPath.row].title
|
||||||
let contentData = tableData[indexPath.section].item[indexPath.row].content
|
let contentData = tableData[indexPath.section].item[indexPath.row].content
|
||||||
|
cell.isPasswordCell = (titleData == "password" ? true : false)
|
||||||
cell.cellData = LabelTableViewCellData(title: titleData, content: contentData)
|
cell.cellData = LabelTableViewCellData(title: titleData, content: contentData)
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue