iOS7键盘返回/完成/search色彩

借助全新的iOS7 UIView色彩,快速为整个应用程序提供主题变得非常简单。 它甚至在编辑UITextField时改变文本插入符号的颜色。

但是,键盘右下angular的“解除”button(可以是完成,search等)始终是蓝色的。 有什么方法可以改变这个吗? 如果它与应用程序的其余部分的色调相匹配,看起来会非常好。

iOS7 UISearchBar键盘

用一点点黑客也许你可以达到你正在寻找的效果。 但它可能无法通过应用程序审查。

-(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)addColorToUIKeyboardButton{ for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) { for (UIView *keyboard in [keyboardWindow subviews]) { for (UIView *view in [self subviewsOfView:keyboard withType:@"UIKBKeyplaneView"]) { UIView *newView = [[UIView alloc] initWithFrame:[(UIView *)[[self subviewsOfView:keyboard withType:@"UIKBKeyView"] lastObject] frame]]; newView.frame = CGRectMake(newView.frame.origin.x + 2, newView.frame.origin.y + 1, newView.frame.size.width - 4, newView.frame.size.height -3); [newView setBackgroundColor:[UIColor greenColor]]; newView.layer.cornerRadius = 4; [view insertSubview:newView belowSubview:((UIView *)[[self subviewsOfView:keyboard withType:@"UIKBKeyView"] lastObject])]; } } } } 

我用来解码视图层次的应用程序是: http : //revealapp.com/

最终的结果是这样的: 绿色钥匙

您不能更改button色调颜色,但可以使用UIKeyboardAppearance设置keyboard色调颜色

图片

例如yourTextField.keyboardAppearance = UIKeyboardAppearanceDark;

这里是苹果提供的一个非常好的文档,看看这里:

pipe理键盘

 let colors: [UIColor] = [.red, .blue, .green, .purple, .yellow, .orange, .brown] if let window = UIApplication.shared.windows.first(where: { $0.isType(string: "UIRemoteKeyboardWindow") }) { if let keyplaneView = window.subview(ofType: "UIKBKeyplaneView") { for (i, keyView) in keyplaneView.subviews.filter({ $0.isType(string: "UIKBKeyView") }).enumerated() { let view = UIView(frame: keyView.bounds) view.backgroundColor = colors[i].withAlphaComponent(0.5) keyView.addSubview(view) } } } 

这里是UIKBKeyplaneView键的颜色映射