iOS8數字鍵台左下角添加完成按鈕

來源:互聯網
上載者:User

標籤:ios8   鍵盤   

iOS8數字鍵台左下角添加完成按鈕的核心代碼如下:

- (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];            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:NUM_PAD_DONE_BUTTON_TAG];                if (doneButton != nil){                    [doneButton removeFromSuperview];                }            }        }    }}

註:

1.iOS8之後,鍵盤view的description變為以<UIInputSetContainerView開頭,所以需要在判斷的邏輯中加上這一項。

2.iOS8之後,鍵盤view的大小變成了整個螢幕的大小,所以需要對按鈕添加的位置進行適配。



iOS8數字鍵台左下角添加完成按鈕

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.