我是iPhone技术的新手.我在iPhone应用程序中保存了一个问题,但是当我使用textfield键盘类型数字键盘时,键盘没有显示返回/完成按钮.
在文本字段中输入数字后如何隐藏数字键盘键盘?你有什么解决方案吗?请提供帮助.
Osc*_*car 11
你可以这样做:
@property (nonatomic, strong) UITextField *textField;
- (void)viewDidLoad {
[super viewDidLoad];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonDidPressed:)];
UIBarButtonItem *flexableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[self class] toobarHeight])];
[toolbar setItems:[NSArray arrayWithObjects:flexableItem,doneItem, nil]];
self.textField.inputAccessoryView = toolbar;
}
- (void)doneButtonDidPressed:(id)sender {
[self.textField resignFirstResponder];
}
+ (CGFloat)toolbarHeight {
// This method will handle the case that the height of toolbar may change in future iOS.
return 44.f;
}
Run Code Online (Sandbox Code Playgroud)
你必须使用UIKeyboardTypeNumberPad,试试这个而不是UIKeyboardTypeNumbersAndPunctuation,它不仅会显示返回键,还会为你提供一些额外的标点符号
| 归档时间: |
|
| 查看次数: |
19976 次 |
| 最近记录: |