alerts-and-pickers
alerts-and-pickers copied to clipboard
Get text of textfield
How do I get the text of the text field in the OneTextfield picker ??
extension UIViewController {
func simpleAlertTextView(title:String, message:String = "", placeHolder:String = "Write here...", style:UIAlertController.Style = .alert, comple: @escaping (String)->()) {
var text = ""
let alert = UIAlertController(style: style, title: title, message: message)
let config: TextField.Config = { textField in
textField.becomeFirstResponder()
textField.textColor = .black
textField.placeholder = placeHolder
textField.left(image: #imageLiteral(resourceName: "icons8-pencil"), color: .gray)
textField.leftViewPadding = 12
textField.borderWidth = 1
textField.cornerRadius = 8
textField.borderColor = UIColor.lightGray.withAlphaComponent(0.5)
textField.backgroundColor = nil
textField.keyboardAppearance = .default
textField.keyboardType = .default
textField.returnKeyType = .done
textField.action { textF in
print("textField.text!: \(textField.text!)")
text = textField.text ?? ""
}
}
alert.addOneTextField(configuration: config)
alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { (action) in
comple(text)
}))
alert.addAction(title: "Cancel", style: .cancel)
alert.show()
}
}
// usage
simpleAlertTextView(title: "Event", message: "Please add event with exact date", style: .actionSheet) { (text) in
print("event submited: \(text)")
}