0

Hi I am new to swift and I have implemented a picker view that alter the text in my UITextField.

However the keyboard cursor will still show up, is there any way to remove the keyboard cursor?

2 Answers2

0

Simple

Go to storyboard -> Select textfield -> properties -> set tint color to clear color

Or UITextField.appearance().tintColor = UIColor.clear

Chanchal Warde
  • 983
  • 5
  • 17
  • Thanks! Even though I am able to type in the emulator, i am assuming i cannot type using my phone becos the keyboard didn't come up which is what i want –  Jan 30 '17 at 10:06
  • May I know if you know how to disable copy and pasting ? becos i realize that i am still able to copy and paste into my UI Text Field –  Jan 30 '17 at 10:07
  • Yubin try some searching first, there are so many answers for this . http://stackoverflow.com/questions/29596043/how-to-disable-pasting-in-a-textfield-in-swift override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { if action == #selector(copy(_:)) || action == #selector(paste(_:)) { return false } return true } – Chanchal Warde Jan 30 '17 at 10:17
0

Implement this method in your UITextFieldDelegate:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    return false
}

This disables typing, copy&pasting and deleting.

If you prefer to not show the keyboard or cursor at all, you can avoid the textfield to become the first responder and show your custom picker instead:

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
    // Show your picker here, and return false to avoid showing keyboard
    return false
}
redent84
  • 18,901
  • 4
  • 62
  • 85
  • thanks but is there any example on how am i suppose to copy this into my UITextFieldDelegate? –  Jan 30 '17 at 10:14