When entering the price, the keyboard that pops out can only have digits and decimal points. The pop-up keyboard doesn’t have the completion key. You can click exit if you want to exit the keyboard, but for a better user experience, add a UI Toolbar to the keyboard.
Set ToolBar:
- (UIToolbar *)addToolbar { UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 30)]; toolbar.tintColor = [UIColor blackColor]; toolbar.backgroundColor = [UIColor lightGrayColor]; UIBarButtonItem *prevItem = [[UIBarButtonItem alloc] initWithTitle:@" < " style:UIBarButtonItemStylePlain target:self action:@selector(prevTextField:)]; UIBarButtonItem *nextItem = [[UIBarButtonItem alloc] initWithTitle:@" > " style:UIBarButtonItemStylePlain target:self action:@selector(nextTextField:)]; UIBarButtonItem *flbSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"complete",nil) style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone)]; toolbar.items = @[prevItem,nextItem,flbSpace, doneItem]; return toolbar; }
Add ToolBar: to textField
_textField.inputAccessoryView = [self addToolbar];
To achieve the effect picture: