Last active
January 18, 2018 20:40
-
-
Save bill350/c4af016c227a4893d6421f81da638dfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Reusable | |
class FormTextFieldTableViewCell: UITableViewCell, NibReusable, FormConformity { | |
@IBOutlet weak var ibTextField: UITextField! | |
var formItem: FormItem? | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
self.ibTextField.addTarget(self, action: #selector(textFieldDidChanged(_:)), for: .editingChanged) | |
} | |
@objc func textFieldDidChanged(_ textField: UITextField) { | |
self.formItem?.valueCompletion?(textField.text) | |
} | |
} | |
// MARK: - FormUpdatable | |
extension FormTextFieldTableViewCell: FormUpdatable { | |
func update(with formItem: FormItem) { | |
self.formItem = formItem | |
self.ibTextField.text = self.formItem?.value | |
let bgColor: UIColor = self.formItem?.isValid == false ? .red : .white | |
self.ibTextField.layer.backgroundColor = bgColor.cgColor | |
self.ibTextField.placeholder = self.formItem?.placeholder | |
self.ibTextField.keyboardType = self.formItem?.uiProperties.keyboardType ?? .default | |
self.ibTextField.tintColor = self.formItem?.uiProperties.tintColor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment