iOS8数字键盘加左下角完成button的核心代码如下面:

- (void)addDoneButtonToNumPadKeyboard
{
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
if (systemVersion < 8.0){
doneButton.frame = CGRectMake(0, 163, 106, 53);
}else{
doneButton.frame = CGRectMake(0, SCREEN_SIZE.height-53, 106, 53);
}
doneButton.tag = NUM_PAD_DONE_BUTTON_TAG;
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"完毕" forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside]; NSArray *windowArr = [[UIApplication sharedApplication] windows];
if (windowArr != nil && windowArr.count > 1){
UIWindow *needWindow = [windowArr objectAtIndex:1];
UIView *keyboard;
for(int i = 0; i < [needWindow.subviews count]; i++) {
keyboard = [needWindow.subviews objectAtIndex:i];
NSLog(@"%@", [keyboard description]);
if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) || ([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) || ([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)){ UIView *doneButtonView = [keyboard viewWithTag:NUM_PAD_DONE_BUTTON_TAG];
if (doneButtonView == nil){
[keyboard addSubview:doneButton];
}
}
}
}
} -(void)removeDoneButtonFromNumPadKeyboard
{
UIView *doneButton = nil; NSArray *windowArr = [[UIApplication sharedApplication] windows];
if (windowArr != nil && windowArr.count > 1){
UIWindow *needWindow = [windowArr objectAtIndex:1];
UIView *keyboard;
for(int i = 0; i < [needWindow.subviews count]; i++) {
keyboard = [needWindow.subviews objectAtIndex:i];
if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) || ([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) || ([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)){
doneButton = [keyboard viewWithTag:NUM_PAD_DONE_BUTTON_TAG];
if (doneButton != nil){
[doneButton removeFromSuperview];
}
}
}
}
}

注:

1.iOS8之后,键盘view的description变为以<UIInputSetContainerView开头,所以须要在推断的逻辑中加上这一项。

2.iOS8之后。键盘view的大小变成了整个屏幕的大小。所以须要对button加入的位置进行适配。

版权声明:本文博主原创文章,博客,未经同意不得转载。

iOS8数字键盘加左下角完成button的更多相关文章

  1. iOS 系统数字键盘左下角加确定按钮

    首先在 viewWillAppear 方法中注册监听相应的键盘通知,并且要在 viewWillDisappear 方法中注销通知- (void)viewWillAppear:(BOOL)animate ...

  2. ios在数字键盘左下角添加“完成”按钮的实现原理

    本文转载至 http://www.itnose.net/detail/6145865.html 最近要在系统弹出的数字键盘上的左下角额外添加一个自定制的完成按钮,于是研究了一下系统自带键盘添加自定制按 ...

  3. iOS数字键盘自定义按键

    UIKeyboardTypeNumberPad 数字键盘自定义按键 最近做一个搜索用户的功能,这里使用了UISearchBar.由于搜索的方式只有手机号码,所以这里的键盘要限制为数字输入,可以这么做: ...

  4. pjsip视频通信开发(上层应用)之数字键盘的制作

    在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重 ...

  5. Android 自定义控件 EditText输入框两边加减按钮Button

    自己封装的一个控件:EditText两边放加减按钮Button来控制输入框的数值 Demo 下载地址: 第一版:http://download.csdn.net/detail/zjjne/674086 ...

  6. (译)iPhone: 用公开API创建带小数点的数字键盘 (OS 3.0, OS 4.0)

    (译)iPhone: 用公开API创建带小数点的数字键盘 (OS 3.0, OS 4.0) 更新:ios4.1现在已经将这个做到SDK了.你可以设置键盘类型为UIKeyboardTypeDecimal ...

  7. ios自定义数字键盘

    因为项目又一个提现的功能,textfiled文本框输入需要弹出数字键盘,首先想到的就是设置textfiled的keyboardType为numberPad,此时你会看到如下的效果:   但是很遗憾这样 ...

  8. h5 调起ios数字键盘的坑,限制特殊字符输入方案

    最近有个需求是利率只允许输入数字和小数点,用以下 <input type="number" pattern="[0-9]*"> 在ios会调起数字键 ...

  9. UIKeyboardTypeNumberPad 数字键盘添加完成按钮

    一:添加通知 //数字键盘添加完成 [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWi ...

随机推荐

  1. A Game of Thrones(20) - Eddard

    Eddard Stark rode through the towering bronze doors of the Red Keep sore, tired, hungry, and irritab ...

  2. 【错误】expected constructor, destructor, or type conversion before '.' token - 第八个游侠的日志 - 网易博客

    [错误]expected constructor, destructor, or type conversion before '.' token - 第八个游侠的日志 - 网易博客 [错误]expe ...

  3. 什么是Java “实例化”

    实例化:对象也是引用数据类型,只能使用new运算符从堆中分配内存: 使用已经定义好的类,创建该类对象的过程称为“实例化”. 只有先实例化类的对象,才可以访问到类中的成员(属性和方法). 使用成员运算符 ...

  4. VMware中linux与window目录共享

    在虚拟机下来实如今windows下共享一个目录: (前提已安装完毕vmtools:http://blog.csdn.net/pipisorry/article/details/21318931) 打开 ...

  5. Hbase经常使用命令

    hbase shell命令的使用 再使用hbase 命令之前先检查一下hbase是否执行正常 hadoop@Master:/usr/hbase/bin$ jps 2640 HMaster 27170 ...

  6. 模拟spring框架注入实现原理

    这个我是参见了别人的一些东西,不是原创! 定义一些抽象的方法: package com.huxin.springinject.dao; public interface Person { public ...

  7. poj2226(最小点覆盖)

    传送门:Muddy Fields 题意:一个由r行c列方格组成的田地,里面有若干个方格充满泥泞,其余方格都是草.要用长度不限,宽度为1的长木板来覆盖这些泥方格,但不能覆盖草地.最少要用多少个长木板. ...

  8. 怎样用Google APIs和Google的应用系统进行集成(1)----Google APIs简介

    Google的应用系统提供了非常多的应用,比方 Google广告.Google 任务,Google 日历.Google blogger,Google Plus,Google 地图等等非常的多的应用,请 ...

  9. SE 2014年4月2日

    一 描述OSPF协议 LSA(Type 1~5)的名称,始发者以及特点 第一类LSA (router lsa)该类lSA为启动了ospf进程的所有路由器都可以产生,该类LSA主要含有本地路由器的接口状 ...

  10. JPush极光推送 Java调用服务器端API开发

       极光推送是:使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动,从而有效地提高留存率,提升用户体验.简单的说就是通过JPush后台管理网站进行app消息的推送.可以让用户及时 ...