Skip to content

Instantly share code, notes, and snippets.

@YoonjaeYoo
Created December 17, 2012 01:20
Show Gist options
  • Save YoonjaeYoo/4315075 to your computer and use it in GitHub Desktop.
Save YoonjaeYoo/4315075 to your computer and use it in GitHub Desktop.
Input accessory view for UITextField or UITextView that has previous, next and done button.
UIToolbar *toolBar = [[UIToolbar alloc] init];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;
[toolBar sizeToFit];
textField.inputAccessoryView = toolBar;
[toolBar release];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", nil), NSLocalizedString(@"Next", nil), nil]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
[segmentedControl addTarget:self action:@selector(textFieldSegmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *previousNextButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(textFieldDoneButtonClicked:)];
toolBar.items = [NSArray arrayWithObjects:previousNextButton, space, doneButton, nil];
[previousNextButton release];
[space release];
[doneButton release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment