uikeyboard

How to make return key on iPhone make keyboard disappear?

帅比萌擦擦* 提交于 2019-11-26 15:14:59
问题 I have two UITextFields (e.g. username and password) but I cannot get rid of the keyboard when pressing the return key on the keyboard. How can I do this? 回答1: First you need to conform to the UITextFieldDelegate Protocol in your View/ViewController's header file like this: @interface YourViewController : UIViewController <UITextFieldDelegate> Then in your .m file you need to implement the following UITextFieldDelegate protocol method: - (BOOL)textFieldShouldReturn:(UITextField *)textField {

UITextView cursor below frame when changing frame

南楼画角 提交于 2019-11-26 13:18:54
问题 I have a UIViewCOntroller that contains a UITextView . When the keyboard appears I resize it like this: #pragma mark - Responding to keyboard events - (void)keyboardDidShow:(NSNotification *)notification { NSDictionary* info = [notification userInfo]; CGRect keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect newTextViewFrame = self.textView.frame; newTextViewFrame.size.height -= keyboardSize.size.height + 70; self.textView.frame = newTextViewFrame; self

Change text of “Return” keyboard button

ぐ巨炮叔叔 提交于 2019-11-26 12:22:53
问题 How can I change the standard text of the \"Return\" button to something else? I want it to be \"Add\". 回答1: Unfortunately, you can change "Return" into only one of these predefined labels with the returnKeyType property: Return (default) Go Google Join Next Route Search Send Yahoo Done Emergency Call Continue (as of iOS 9) So maybe you should choose "Next" if a data entry kind of activity is what you're after. More information here. 回答2: You can use this simple way: [textField

How to dismiss keyboard when touching anywhere outside UITextField (in swift)?

陌路散爱 提交于 2019-11-26 11:57:43
问题 I\'m working on a project that have a UIViewController, on the view controller there is a UIScrollView and a UITextField on the scrollview. like this: I\'m trying to dismiss the keyboard and hide it after typing some text in the textfield and tap anywhere outside the textfield. I\'ve tried the following code: override func viewDidLoad() { super.viewDidLoad() self.textField.delegate = self; } override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { self.view.endEditing

Keyboard not Appearing when Tapping Text Box in UIWebView

喜欢而已 提交于 2019-11-26 11:39:33
问题 I have a UITabViewController set up with two tabs, the second containing a web browser. The keyboard will not appear in my App unless I first display and dismiss a UIAlertView in the first tab. What could possibly be wrong? 回答1: Solved; I accidentally removed: [window makeKeyAndVisible]; 回答2: The solution mentioned here didn't work for me. I had a persistent error that seemed to be an issue with iOS, or at least my build settings. I came up with a workaround. If you're still stuck like I was,

Close iOS Keyboard by touching anywhere using Swift

谁都会走 提交于 2019-11-26 11:27:27
I have been looking all over for this but I can't seem to find it. I know how to dismiss the keyboard using Objective-C but I have no idea how to do that using Swift ? Does anyone know? Esqarrouth override func viewDidLoad() { super.viewDidLoad() //Looks for single or multiple taps. let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard") //Uncomment the line below if you want the tap not not interfere and cancel other interactions. //tap.cancelsTouchesInView = false view.addGestureRecognizer(tap) } //Calls this function when the tap is recognized.

Dismiss keyboard by touching background of UITableView

∥☆過路亽.° 提交于 2019-11-26 11:03:29
I have a UITableView with UITextField s as cells. I would like to dismiss the keyboard when the background of the UITableView is touched. I'm trying to do this by creating a UIButton the size of the UITableView and placing it behind the UITableView . The only problem is the UIButton is catching all the touches even when the touch is on the UITableView. What am I doing wrong? Thanks! mixja This is easily done by creating a UITapGestureRecognizer object (by default this will detect a "gesture" on a single tap so no further customization is required), specifying a target/action for when the

Programmatically change UITextField Keyboard type

醉酒当歌 提交于 2019-11-26 10:09:24
问题 Is it possible to programmatically change the keyboard type of a uitextfield so that something like this would be possible: if(user is prompted for numeric input only) [textField setKeyboardType: @\"Number Pad\"]; if(user is prompted for alphanumeric input) [textField setKeyboardType: @\"Default\"]; 回答1: There is a keyboardType property for a UITextField : typedef enum { UIKeyboardTypeDefault, // Default type for the current input method. UIKeyboardTypeASCIICapable, // Displays a keyboard

How to get height of Keyboard?

ⅰ亾dé卋堺 提交于 2019-11-26 08:01:51
问题 The height of a keyboard on varying iOS devices is different. Does anybody know how I can get height of a device\'s keyboard programmatically? 回答1: In Swift: You can get the keyboard height by subscribing to the UIKeyboardWillShowNotification notification. (Assuming you want to know what the height will be before it's shown). Something like this: Swift 2 NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)

Allow only Numbers for UITextField input

孤街浪徒 提交于 2019-11-26 03:54:57
问题 The iPad does not have a \"Numpad\" keyboard like the iPhone/iPod does. I\'m looking to find how I can restrict the user\'s keyboard to only accept values 0 through 9. I would imagine using UITextField\'s \"shouldChangeCharactersInRange\" but I don\'t know the best way to implement it. 回答1: This is how you might handle the problem on a SSN verification field, you can modify the max length and remove the if statement checking for keyboard type if you need to. There is also logic to suppress