passforios/pass/Views/FillPasswordTableViewCell.swift

45 lines
1.3 KiB
Swift
Raw Normal View History

//
// FillPasswordTableViewCell.swift
// pass
//
// Created by Mingshen Sun on 11/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
protocol FillPasswordTableViewCellDelegate {
func generatePassword() -> String
}
2017-02-13 01:15:42 +08:00
class FillPasswordTableViewCell: ContentTableViewCell {
@IBOutlet weak var contentTextField: UITextField!
var delegate: FillPasswordTableViewCellDelegate?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func generatePassword(_ sender: UIButton) {
let plainPassword = self.delegate?.generatePassword() ?? Utils.generatePassword(length: 16)
2017-02-26 00:58:18 +08:00
contentTextField.attributedText = Utils.attributedPassword(plainPassword: plainPassword)
Utils.copyToPasteboard(textToCopy: plainPassword)
}
2017-02-13 01:15:42 +08:00
override func getContent() -> String? {
2017-02-26 00:58:18 +08:00
return contentTextField.attributedText?.string
2017-02-13 01:15:42 +08:00
}
override func setContent(content: String) {
2017-02-26 00:58:18 +08:00
contentTextField.attributedText = Utils.attributedPassword(plainPassword: content)
2017-02-13 01:15:42 +08:00
}
}