IOS数字键盘左下角添加完成按钮的实现方法
程序员文章站
2023-12-21 00:02:16
ios数字键盘左下角添加完成按钮的实现方法
实现代码:
- (void)adddonebuttontonumpadkeyboard
{
uibutt...
ios数字键盘左下角添加完成按钮的实现方法
实现代码:
- (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]; } } } } }
以上就是ios数字键盘左下角添加完成按钮的实现方法,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!