使用新的 iOS7 UIView 色调颜色,可以很容易地快速为整个应用程序设置主题。它甚至在编辑 UITextField 时更改文本插入符号的颜色。
但是,键盘右下角的“关闭”按钮(可以是完成、搜索等)始终为蓝色。有什么办法可以改变这个吗?如果它与应用程序其余部分的色调相匹配,它看起来会非常好。
使用新的 iOS7 UIView 色调颜色,可以很容易地快速为整个应用程序设置主题。它甚至在编辑 UITextField 时更改文本插入符号的颜色。
但是,键盘右下角的“关闭”按钮(可以是完成、搜索等)始终为蓝色。有什么办法可以改变这个吗?如果它与应用程序其余部分的色调相匹配,它看起来会非常好。
通过一点技巧,也许你可以达到你想要的效果。但它可能无法通过应用审查。
-(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/
最终结果是这样的:
您不能更改按钮色调颜色,但您可以keyboard
使用设置色调颜色 UIKeyboardAppearance
示例:yourTextField.keyboardAppearance = UIKeyboardAppearanceDark;
这是Apple提供的一个非常好的文档,请看这里:
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
: