Joey Carson
Joey Carson

Reputation: 3113

How can I override the extended keyboard toolbar on the iOS 9 virtual keyboard?

The virtual keyboard in iOS 9 brings undo, redo, and paste controls. I notice that in my app, they're always the same but in Safari and others, they're different with customizations. I have a custom toolbar already as the inputAccessoryView and I'd rather have it there than the iOS supplied controls. I've looked around but I can't see anything that allows for overriding it with my view. Is there a way to do so?

Upvotes: 3

Views: 1105

Answers (1)

arlomedia
arlomedia

Reputation: 9061

In Luke's comment to the original post, he described UITextInputAssistantItem as a private API. It's true this class does not yet appear in the iOS 9 SDK documentation, but it does appear in the iOS 9 release notes, and was introduced at WWDC (session 107; search for "assistant"), so it seems okay to use and discuss.

Here's some sample code provided by an Apple employee on their public forum:

NSArray barButtonItems = @[ /* Create UIBarButtonItems and place them here */ ];  
UIBarButtonItem representativeItem = // This is optional, if present when there isn't enough room on the bar, the group will be replaced with this item  
UIBarButtonItemGroup *group = [[UIBarButtonItemGroup alloc] initWithBarButtonItems:barButtonItems representativeItem:representativeItem]  
textView.inputAssistantItem.leadingBarButtonGroups = @[ group ]; // replace the items on the bar. Alternatively you can append this group and get the default leading items with this extra group  

Upvotes: 1

Related Questions