首页 > 移动平台 > 详细

iOS为数字键盘增加完成按钮

时间:2018-09-01 10:09:52      阅读:250      评论:0      收藏:0      [点我收藏+]

在输入价格的时候,要求弹出的键盘只能有数字和小数点。弹出的键盘没有完成键,想要退出键盘可以点击退出,但是为了更好的用户体验,在键盘上增加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为数字键盘增加完成按钮

原文:https://www.cnblogs.com/xuzb/p/9569158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!