借助新的 iOS7 UIView 色调颜色,可以非常轻松地快速为整个应用设置主题。它甚至会在编辑 UITextFields 时更改文本插入符号的颜色。
但是,键盘右下角的“关闭”按钮(可以是“完成”、“搜索”等)始终是蓝色的。有什么办法可以改变这个吗?如果它与应用程序其余部分的色调相匹配,它看起来会非常漂亮。
最佳答案
通过一些技巧,也许您可以达到您想要的效果。但它可能无法通过应用审核。
-(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])];
}
}
}
}
我用来解码 View 层次结构的应用程序是:http://revealapp.com/
最终结果是这样的:
关于iOS7 键盘返回/完成/搜索色调颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19465765/