標籤:分享圖片 frame oca tco ntc button png 數字 tle
在輸入價格的時候,要求彈出的鍵盤只能有數字和小數點。彈出的鍵盤沒有完成鍵,想要退出鍵盤可以點擊退出,但是為了更好的使用者體驗,在鍵盤上增加UIToolbar。
設定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(@"完成",nil) style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone)]; toolbar.items = @[prevItem,nextItem,flbSpace, doneItem]; return toolbar;}
為textField添加ToolBar:
_textField.inputAccessoryView = [self addToolbar];
實現:
iOS為數字鍵台增加完成按鈕