alerts-and-pickers icon indicating copy to clipboard operation
alerts-and-pickers copied to clipboard

Get text of textfield

Open AbrahamEP opened this issue 6 years ago • 1 comments

How do I get the text of the text field in the OneTextfield picker ??

AbrahamEP avatar Apr 20 '18 21:04 AbrahamEP

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)")
 }

HappyIosDeveloper avatar Apr 17 '19 08:04 HappyIosDeveloper