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

前端 未结 3 1464
别跟我提以往
别跟我提以往 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.

    0 讨论(0)
  • 2021-01-02 13:41

    As Ben states above you can just use one of these two values:

    [textView setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [textView setKeyboardAppearance:UIKeyboardAppearanceDefault];
    
    0 讨论(0)
  • 2021-01-02 13:48

    The short answer is, NO. The only two keyboards you can display are the normal and alert style keyboards.

    There are ways to hack around, get the ui keyboard and change it's composition. I wouldn't recommend doing this as it will 1) likely make have your app rejected from the app store and 2) likely break the next time an iOS revision comes around.

    Seems like putting a black or white view behind the keyboard should work for application. In this case I would recommend looking here for a way to animate that black view up below the keyboard.

    0 讨论(0)
提交回复
热议问题