b2cloud

20th February 2013

Keyboard add-ons (accessories) and custom keyboards in iOS

Guides | Tutorial By 4 years ago

When the standard keyboard is not enough a keyboard accessory is often a good solution. I am talking of the one commonly seen in web apps, allowing the user to go between fields and drop the keyboard.

 

These are extremely easy to add, and require very little code. In your UITextField you need to set the inputAccessoryView. This can take any UIView subclass and will display just like a regular keyboard, all animations are handled for you

//	Your UITextField...
UITextField* textField = nil;

UIView* inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[inputAccessoryView setBackgroundColor:[UIColor redColor]];

[textField setInputAccessoryView:inputAccessoryView];

Too easy:

 

You may have also noticed the inputView property. This allows you to set a custom keyboard:

//	Your UITextField...
UITextField* textField = nil;

UIView* inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 216)];
[inputView setBackgroundColor:[UIColor redColor]];

[textField setInputView:inputView];

 

Of course, these can both be used in conjunction with each other:

//	Your UITextField...
UITextField* textField = nil;

UIView* inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 216)];
[inputView setBackgroundColor:[UIColor blueColor]];

[textField setInputView:inputView];

UIView* inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[inputAccessoryView setBackgroundColor:[UIColor redColor]];

[textField setInputAccessoryView:inputAccessoryView];

Recommended Posts

Yammer integrations in ReactJS

Post by 4 years ago

I am writing this blog while I am working on a project for our client’s intranet website. The client requires the website has the ability to share, like and write comments in the website through

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!