给数字键盘添加完成按钮

这里面有个问题,在6P上不显示

- (void)addDoneButtonToNumPadKeyboard
{
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    if (IOS_8_OR_LATER == 0){
//        doneButton.frame = CGRectMake(0, 3*(self.boardHeight-3)/4.0f, (kScreenWidth-4)/3.0f, (self.boardHeight-3)/4.0f);
//    }else{
//        doneButton.frame = CGRectMake(0, kScreenHeight-(self.boardHeight-3)/4.0f, (kScreenWidth-4)/3.0f, (self.boardHeight-3)/4.0f);
//    }
    if (IOS_8_OR_LATER == 0){
        doneButton.frame = CGRectMake(0, 163, 106, 53);
    }else{
        doneButton.frame = CGRectMake(0, kScreenHeight-53, 106, 53);
    }
    doneButton.backgroundColor = [UIColor redColor];
    doneButton.tag = 100000000;
    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];
            if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) || ([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) || ([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)){
                if ([[keyboard subviews] count] <= 1){
                    [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:100000000];
                if (doneButton != nil){
                    [doneButton removeFromSuperview];
                }
            }
        }
    }
}

- (void)doneButton:(UIButton *)doneButton
{
    [self.view endEditing:YES];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,911评论 25 709
  • 上一篇《暖耳的白金温柔,漫步者W830BT蓝牙耳机开箱篇》笔点君已经对漫步者W830BT的外观和细节做了点评。但养...
    笔点酷玩阅读 7,856评论 0 4
  • 前文作者一直在启发整个超级IP的体系逻辑,发展过程,今天的两篇主要讲述了如何打造超级IP。 首先你要聚焦自己的客户...
    子午斓阅读 1,270评论 0 0
  • “再见”这个词,总是会用在告别的时候,寓意着“还会再相见”,可是,很长时间以来,我却一直觉得“再见,就是再也不见”...
    成长之鱼阅读 3,294评论 0 0

友情链接更多精彩内容