
It's easy, so easy, it makes you a tiny bit happy inside once you see how easy it is. I'll post the code then give an explanation for those of you that want more.
CODE:
// create a done view + done button, attach to it a doneClicked action, and place it in a toolbar as an accessory input view...
// Prepare done button
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView.barStyle = UIBarStyleBlack;
keyboardDoneButtonView.translucent = YES;
keyboardDoneButtonView.tintColor = nil;
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerDoneClicked:)];
// I put the spacers in to push the doneButton to the right side of the picker view
UIBarButtonItem *spacer1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
// I put the spacers in to push the doneButton to the right side of the picker view
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:spacer, spacer1, doneButton, nil]];
// Plug the keyboardDoneButtonView into the text field...
self.businessType.inputAccessoryView = keyboardDoneButtonView;
Bam, and you are done.
Explanation:For nearly every input field (I focus on the
UITextField here) in objective-C iOS you can choose one of the core SDK libraries input tools to pop up, whether this is a keyboard or a picker, or one of the many others to choose from. You simply need to assign the input tool to the
inputview, but what I stumbled across is Apple so graciously made an additional built in view to give you just a touch more creative flexiblity, it's the
inputAccessoryView and it sits on top of the
inputView. All you have to do is stuff another view into the
inputAccessoryView. I imagine you could put whatever you want, but a
UIToolbar seems to be the unspoken consensus on what to use. Put a few buttons in the
UIToolbar and set it as the
inputAccessoryView. Done. Yeah. It's not complex, but a nice to have.
Easy enough!