Skip to content

Instantly share code, notes, and snippets.

@MylesCaley
Created March 15, 2017 20:40
Show Gist options
  • Save MylesCaley/4f5f506a52ad0c3dd0aeafd2e0413768 to your computer and use it in GitHub Desktop.
Save MylesCaley/4f5f506a52ad0c3dd0aeafd2e0413768 to your computer and use it in GitHub Desktop.
blink cursor in textfield without showing keyboard
@yimikailori
Copy link

yimikailori commented Apr 30, 2019

put it under your viewload and for swift 5
note change inputTextField to the your input variable name

  self.inputTextField.becomeFirstResponder()
  //re-enable for when user actually clicks
  let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(InTextFieldTapped(_:)))
  inputTextField.addGestureRecognizer(tapGuesture)

  then after the viewload function add this function
  @IBAction func InTextFieldTapped(_ gesture: UITapGestureRecognizer) {
        if gesture.state == .ended {
            view.endEditing(true)
            inputTextField.inputView = nil 
            inputTextField.becomeFirstResponder()
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment