Can I tint (black) a UIKeyboard? If so, how?

前端 未结 3 1495
别跟我提以往
别跟我提以往 2021-01-02 13:11

Is there a way to get a black keyboard? The default one is bluish. And the Alert style one is semi-transparent black. I was wondering if it was possible to have the keyboard

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 13:28

    Here is code to remove the UIKeyboard background by hiding it. Feel free to modify it to tint the UIKeyboard:

    -(NSArray*)subviewsOfView:(UIView*)view withType:(NSString*)type{
    NSString *prefix = [NSString stringWithFormat:@"<%@",type];
    NSMutableArray *subviewArray = [NSMutableArray array];
    for (UIView *subview in view.subviews) {
        NSArray *tempArray = [self subviewsOfView:subview withType:type];
        for (UIView *view in tempArray) {
            [subviewArray addObject:view];
        }
    }
    if ([[view description]hasPrefix:prefix]) {
        [subviewArray addObject:view];
    }
    return [NSArray arrayWithArray:subviewArray];
    }
    
    -(void)removeKeyboardBackground{
        for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
            for (UIView *keyboard in [keyboardWindow subviews]) {
                for (UIView *view in [self subviewsOfView:keyboard withType:@"UIKBBackgroundView"]) {
                    view.hidden=YES;
                }
            }
        }
    }
    

    Just call [self removeKeyboardBackground] after you received a NSNotification for UIKeyboardDidShowNotification. Do whatever you want with the background view by replacing view.hidden=YES; with whatever you would like.

提交回复
热议问题