使用新的iOS7 UIView色调,可以快速主题化整个应用程序。它甚至在编辑UITextFields时会改变文本插入符的颜色。
但是,键盘的右下方“关闭”按钮(可以是“完成”,“搜索”等)始终为蓝色。有没有办法改变这个?如果它与应用程序其余部分的色调相匹配,那将会非常好看。
答案 0 :(得分:32)
通过一点点黑客,你可以达到你想要的效果。但它可能无法通过应用审核。
-(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/
最终结果如下:
答案 1 :(得分:4)
您无法更改按钮色调颜色,但可以使用keyboard
UIKeyboardAppearance
色调颜色
示例:yourTextField.keyboardAppearance = UIKeyboardAppearanceDark;
这是Apple提供的一个非常好的文档,请看这里:
答案 2 :(得分:0)
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
: