|
@@ -21,19 +21,23 @@ class TextFieldCell: UITableViewCell {
|
|
|
return textField
|
|
|
}()
|
|
|
|
|
|
- init(description: String, placeholder: String) {
|
|
|
- self.placeholder = placeholder
|
|
|
+ init(description: String, placeholder: String) {
|
|
|
+ self.placeholder = placeholder
|
|
|
|
|
|
- super.init(style: .value1, reuseIdentifier: nil)
|
|
|
+ super.init(style: .value1, reuseIdentifier: nil)
|
|
|
|
|
|
- textLabel?.text = "\(description):"
|
|
|
+ textLabel?.text = "\(description):"
|
|
|
|
|
|
- // see: https://stackoverflow.com/a/35903650
|
|
|
- // this makes the textField respect the trailing margin of
|
|
|
- // the table view cell
|
|
|
- selectionStyle = .none
|
|
|
- setupViews()
|
|
|
- }
|
|
|
+ // see: https://stackoverflow.com/a/35903650
|
|
|
+ // this makes the textField respect the trailing margin of
|
|
|
+ // the table view cell
|
|
|
+ selectionStyle = .none
|
|
|
+ setupViews()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder _: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
|
|
|
private func setupViews() {
|
|
|
contentView.addSubview(textField)
|
|
@@ -43,65 +47,67 @@ class TextFieldCell: UITableViewCell {
|
|
|
textField.trailingAnchor.constraint(equalTo: trailing).isActive = true
|
|
|
textField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
|
|
if let label = self.textLabel {
|
|
|
- textField.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20).isActive = true
|
|
|
+ textField.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20).isActive = true // this will prevent the textfield from growing over the textLabel while typing
|
|
|
} else {
|
|
|
textField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20).isActive = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override func setSelected(_ selected: Bool, animated _: Bool) {
|
|
|
- if selected {
|
|
|
- textField.becomeFirstResponder()
|
|
|
+ override func setSelected(_ selected: Bool, animated _: Bool) {
|
|
|
+ if selected {
|
|
|
+ textField.becomeFirstResponder()
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- required init?(coder _: NSCoder) {
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
- }
|
|
|
+ func getText() -> String? {
|
|
|
+ return self.textField.text
|
|
|
+ }
|
|
|
|
|
|
- static func makeEmailCell() -> TextFieldCell {
|
|
|
- let emailCell = TextFieldCell(description: "Email", placeholder: "you@example.com")
|
|
|
|
|
|
- emailCell.textField.keyboardType = .emailAddress
|
|
|
- // switch off quicktype
|
|
|
- emailCell.textField.autocorrectionType = .no
|
|
|
- emailCell.textField.autocapitalizationType = .none
|
|
|
|
|
|
- return emailCell
|
|
|
- }
|
|
|
+ static func makeEmailCell() -> TextFieldCell {
|
|
|
+ let emailCell = TextFieldCell(description: "Email", placeholder: "you@example.com")
|
|
|
|
|
|
- static func makePasswordCell() -> TextFieldCell {
|
|
|
- let passwordCell = TextFieldCell(description: "Password", placeholder: "your IMAP password")
|
|
|
+ emailCell.textField.keyboardType = .emailAddress
|
|
|
+ // switch off quicktype
|
|
|
+ emailCell.textField.autocorrectionType = .no
|
|
|
+ emailCell.textField.autocapitalizationType = .none
|
|
|
|
|
|
- passwordCell.textField.textContentType = UITextContentType.password
|
|
|
- passwordCell.textField.isSecureTextEntry = true
|
|
|
+ return emailCell
|
|
|
+ }
|
|
|
|
|
|
- return passwordCell
|
|
|
- }
|
|
|
+ static func makePasswordCell() -> TextFieldCell {
|
|
|
+ let passwordCell = TextFieldCell(description: "Password", placeholder: "your IMAP password")
|
|
|
|
|
|
- static func makeNameCell() -> TextFieldCell {
|
|
|
- let nameCell = TextFieldCell(description: "Name", placeholder: "new contacts nickname")
|
|
|
+ passwordCell.textField.textContentType = UITextContentType.password
|
|
|
+ passwordCell.textField.isSecureTextEntry = true
|
|
|
|
|
|
- nameCell.textField.autocapitalizationType = .words
|
|
|
- nameCell.textField.autocorrectionType = .no
|
|
|
- // .namePhonePad doesn't support autocapitalization
|
|
|
- // see: https://stackoverflow.com/a/36365399
|
|
|
- // therefore we use .default to capitalize the first character of the name
|
|
|
- nameCell.textField.keyboardType = .default
|
|
|
+ return passwordCell
|
|
|
+ }
|
|
|
+
|
|
|
+ static func makeNameCell() -> TextFieldCell {
|
|
|
+ let nameCell = TextFieldCell(description: "Name", placeholder: "new contacts nickname")
|
|
|
|
|
|
- return nameCell
|
|
|
- }
|
|
|
+ nameCell.textField.autocapitalizationType = .words
|
|
|
+ nameCell.textField.autocorrectionType = .no
|
|
|
+ // .namePhonePad doesn't support autocapitalization
|
|
|
+ // see: https://stackoverflow.com/a/36365399
|
|
|
+ // therefore we use .default to capitalize the first character of the name
|
|
|
+ nameCell.textField.keyboardType = .default
|
|
|
|
|
|
- static func makeConfigCell(label: String, placeholder: String) -> TextFieldCell {
|
|
|
- let nameCell = TextFieldCell(description: label, placeholder: placeholder)
|
|
|
+ return nameCell
|
|
|
+ }
|
|
|
|
|
|
- nameCell.textField.autocapitalizationType = .words
|
|
|
- nameCell.textField.autocorrectionType = .no
|
|
|
- // .namePhonePad doesn't support autocapitalization
|
|
|
- // see: https://stackoverflow.com/a/36365399
|
|
|
- // therefore we use .default to capitalize the first character of the name
|
|
|
- nameCell.textField.keyboardType = .default
|
|
|
+ static func makeConfigCell(label: String, placeholder: String) -> TextFieldCell {
|
|
|
+ let nameCell = TextFieldCell(description: label, placeholder: placeholder)
|
|
|
|
|
|
- return nameCell
|
|
|
- }
|
|
|
+ nameCell.textField.autocapitalizationType = .words
|
|
|
+ nameCell.textField.autocorrectionType = .no
|
|
|
+ // .namePhonePad doesn't support autocapitalization
|
|
|
+ // see: https://stackoverflow.com/a/36365399
|
|
|
+ // therefore we use .default to capitalize the first character of the name
|
|
|
+ nameCell.textField.keyboardType = .default
|
|
|
+
|
|
|
+ return nameCell
|
|
|
+ }
|
|
|
}
|