I\'m using a UITextField to show results of a calculation but I don\'t want the keyboard to appear when the user taps on the UIText
For iPads, according to this response of @Awais Jamil, add the following code
textField.inputAssistantItem.leadingBarButtonGroups = []
textField.inputAssistantItem.trailingBarButtonGroups = []
You can hide keyboard in UITextFieldDelegate
method textFieldDidBeginEditing:(textField: UITextField)
like below :
func textFieldDidBeginEditing:(textField: UITextField) {
self.view.endEditing(true)
}
Swift 4.2, This works for me.
put in viewDidLoad()
//It will Hide Keyboard
textField.inputView = UIView()
//It will Hide Keyboard tool bar
textField.inputAccessoryView = UIView()
//It will Hide the cursor
textField.tintColor = .white
Its quite simple to do with UITextField. Use this code in viewDidLoad()
self.txtresult.inputView = UIView()
self.txtresult.inputAccessoryView = UIView()
you could use an "empty" inputview like this:
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
let inputView = UIView(frame: .zero)
inputView.backgroundColor = UIColor.clearColor()
inputView.opaque = false
textField.inputView = inputView
return true
}
First set delegate
with your UITextField
in self
class.
You can do with below 2 ways.
1. From storyboard
2. From Code ( You can write at viewDidLoad()
)
textField.delegate = self
Then declare protocol UITextFieldDelegate
in your class.
Now call delegate method.
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return true
}