UIKeyboardTypeNumberPad 数字键盘添加完成按钮
生活随笔
收集整理的這篇文章主要介紹了
UIKeyboardTypeNumberPad 数字键盘添加完成按钮
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一:添加通知
?//數(shù)字鍵盤添加完成
? ? [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotificationobject:nil];
二:數(shù)字鍵盤出現(xiàn)添加
//鍵盤處理 - (void)keyboardWillShow:(NSNotification *)note {UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];doneButton.frame = CGRectMake(15, 172, 65, 35);//doneButton.frame = CGRectMake(8, 163, 50, 30);//[doneButton setTitle:@"完成" forState:UIControlStateNormal];[doneButton setBackgroundImage:[UIImage imageNamed:@"pickerBackIMG.png"] forState:UIControlStateNormal];[doneButton addTarget:self action:@selector(doneBtn) forControlEvents:UIControlEventTouchUpInside];UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];UIView* keyboard;for(int i=0; i<[tempWindow.subviews count]; i++) {keyboard = [tempWindow.subviews objectAtIndex:i];// keyboard view found; add the custom button to itif(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) ||(([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)))[keyboard addSubview:doneButton];} }- (void)doneBtn {[phoneNumTextField resignFirstResponder];}三:移除通知
- (void)dealloc
{
? ? [[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardDidShowNotificationobject:nil];
? ? [kDatePickerrelease];
? ? [super dealloc];
}
轉(zhuǎn)載于:https://www.cnblogs.com/cocoajin/p/3246321.html
總結(jié)
以上是生活随笔為你收集整理的UIKeyboardTypeNumberPad 数字键盘添加完成按钮的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 买眼镜
- 下一篇: 六、CPU优化(4)NUMA架构