Skip to content

Instantly share code, notes, and snippets.

@bill350
Last active January 18, 2018 20:40
Show Gist options
  • Save bill350/c4af016c227a4893d6421f81da638dfd to your computer and use it in GitHub Desktop.
Save bill350/c4af016c227a4893d6421f81da638dfd to your computer and use it in GitHub Desktop.
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