开发者

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

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 black, e.g. non transparen开发者_JS百科t. Or do I have to pull up a black view behind the keyboard to reduce the transparency effect?


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.


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

[textView setKeyboardAppearance:UIKeyboardAppearanceAlert];
[textView setKeyboardAppearance:UIKeyboardAppearanceDefault];


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜