Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a view on top of keyboard?

I have added a view with buttons on top of keyboard using setInputAccessoryView. Now i want functionality like when i click button from the view i want to display a pickerView on top of keyboard. Means like adding pickerView as subview of keyboard.

How can i do this?

like image 469
user1244311 Avatar asked Oct 04 '12 06:10

user1244311


People also ask

How do I move the view up on keyboard in iOS?

The best way to do this is to place your content inside a UIScrollView, then adjust the scroll view's contentInset property by the height of the keyboard when it's shown. Absolutely do not assume the keyboard height--use the value from the "keyboard will show" notification.

What is Inputaccessoryview?

A component which enables customization of the keyboard input accessory view on iOS. The input accessory view is displayed above the keyboard whenever a TextInput has focus. This component can be used to create custom toolbars.


1 Answers

Make a view you want to at the top of the keyboard. You can do this from xib or manually, but I think xib will be a better option.

Then make the reference to this view by doing this

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
   textField.inputAccessoryView = YOURCustomView;
   return YES;
}

Whenever you want to hide this or remove this just put this

textField.inputAccessoryView = nil;
like image 58
Sham Avatar answered Nov 08 '22 00:11

Sham