iOS为数字键盘增加完成按钮
2024-08-24 12:14:17
在输入价格的时候,要求弹出的键盘只能有数字和小数点。弹出的键盘没有完成键,想要退出键盘可以点击退出,但是为了更好的用户体验,在键盘上增加UIToolbar。
设置ToolBar:
- (UIToolbar *)addToolbar { UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(, , CGRectGetWidth(self.view.frame), )];
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];
实现效果图:
最新文章
- Bzoj4008 [HNOI2015]亚瑟王
- Android——数据的存储和访问
- BeagleBone Black项目实训手册(大学霸内部资料)
- 进程创建函数fork()、vfork() ,以及excel()函数
- Android高清巨图加载方案
- [问题解决] 启动mongod 时,出现addr already in use错误
- 随机获取部分List<;Object>;集合
- WPF之DataContext(转)
- [Swift]LeetCode668. 乘法表中第k小的数 | Kth Smallest Number in Multiplication Table
- Linux的内存机制(转载)
- [转] Understanding Convolutional Neural Networks for NLP
- boost::asio实现一个echo服务器
- 64Bit &; 32Bit HashCode
- [Lua]table(一):打印与复制
- MATLAB中批量导入.mat文件(每个文件多变量)
- CentOS下多网卡绑定多IP段时导致只有一个会通的问题解决
- 第七周:Python
- 了解python wed 框架
- 【转】mxGraph教程-开发入门指南
- 一遍记住Java常用的八种排序算法与代码实现
热门文章
- 【Html基础】之<;h1>;~<;h6>; <;p>; <;br>; <;hr>;
- 解决 客户端连接 mysql5.7 Plugin &#39;mysql_native_plugin&#39; is not loaded错误
- javascript的 热点图怎么写
- Android Editable
- Ubuntu 安装 PhpMyAdmin 图文教程
- 【Oracle】DBMS_STATS.GATHER_TABLE_STATS详解
- C# winfrom界面跳转闪烁问题解决方法
- 实现UIView的无限旋转动画(非CALayer动画)
- 企业级Nginx增加日志选项
- js的一道经典题目