How to hide iOS numeric keypad

I am using a numeric keypad to enter from a UITextField. I noticed that Interface Builder has a return key property called Finish. When I select "Finish" according to the parameters of the return key, I do not see the "Finish" button being created on the numeric keypad. I see the Finish button on other types of keyboards if I change it from the numeric keypad to something else, but not to use the numeric keypad.

  • I want to create a β€œFinish” button on the keyboard that will hide the keyboard when pressed
  • I want to do this because of the amount of real estate that the keyboard occupies.
  • I am very new to iOS development, so the easiest and least confusing way to achieve this goal will be appreciated.

Thanks in advance!

+4
source share
3 answers

A typical way to do this is to assign a toolbar containing a button to the inputAccessoryView property of the text view.

+7
source

I found this solution online, but it involves creating an image for your button: http://www.neoos.ch/blog/37-uikeyboardtypenumberpad-and-the-missing-return-key

You can also use the same method to get the UIKeyboard view shown in the example and do the following as suggested by @Jim:

 UIToolbar *keyboardViewToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 206, 320, 44)]; UIBarButtonItem *keyboardDoneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneSettingDate)]; UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithTitle:@"Enter Number" style:UIBarButtonItemStylePlain target:nil action:nil]; UIBarButtonItem *spacer1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; NSArray *barButtonItems = [[NSArray alloc] initWithObjects:spacer1, title, spacer2, pickerDoneButton, nil]; [keyboardViewToolbar setItems:barButtonItems]; 

And add this view to the keyboard view.

In addition, as a separate offer, given that you are just starting. On iTunes U, you can download iOS Stanford class app development; this is a very comprehensive iOS development course, available for free from the iTunes Store.

0
source
 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { UIToolbar* KeyBoardToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; KeyBoardToolbar.barStyle = UIBarStyleBlackTranslucent; KeyBoardToolbar.items = [NSArray arrayWithObjects: [[UIBarButtonItem alloc]initWithTitle:[GlobalSettings GetTextBySelectedLocale:@"Done"] style:UIBarButtonItemStyleBordered target:self action:@selector(DismissKeyBoard)], [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], nil]; [KeyBoardToolbar sizeToFit]; txtMessage.inputAccessoryView = KeyBoardToolbar; } 

Where txtMessage can be a UiTextField or UITextView .

 -(void)DismissKeyBoard{ [self.view endEditing:YES]; } 
0
source

Source: https://habr.com/ru/post/1413594/


All Articles