您好,登錄后才能下訂單哦!
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數字鍵盤左下角添加完成按鈕的實現方法,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。