iOS7 键盘返回/完成/搜索色调颜色

标签 ios objective-c ios7 uikeyboard

借助新的 iOS7 UIView 色调颜色,可以非常轻松地快速为整个应用设置主题。它甚至会在编辑 UITextFields 时更改文本插入符号的颜色。

但是,键盘右下角的“关闭”按钮(可以是“完成”、“搜索”等)始终是蓝色的。有什么办法可以改变这个吗?如果它与应用程序其余部分的色调相匹配,它看起来会非常漂亮。

iOS7 UISearchBar keyboard

最佳答案

通过一些技巧,也许您可​​以达到您想要的效果。但它可能无法通过应用审核。

-(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/

最终结果是这样的:Green Key

关于iOS7 键盘返回/完成/搜索色调颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19465765/

相关文章:

ios - .xcdatamodeld 文件未在 Xcode 中显示数据模型结构

iphone - ios4.1中出现的错误(*** ERROR : FigCreateCGImageFromJPEG returned -12905. Input (null) was 499992 bytes.)!

objective-c - 尝试在其 View 不在窗口层次结构中的 UIViewController 上呈现 UIAlertController

ios - 如何找到内存警告的真正原因以及如何在iOS应用程序中解决

ios - 在 iOS Collection View 中的单元格顶部显示菜单 Controller

iphone - UITableView didSelectRowAtIndexPath 返回错误的行索引 (iOS7)

ios7 - SpriteNode 不遵循 cgpath

iphone - iOS - 从 appDelegate 访问 Storyboard上的 viewControllers

ios - 专注于输入字段和方向变化会扰乱 iOS 6 Safari 上的缩放级别

iphone - 使用 AVCaptureSession 录制的视频帧