如果我更改 UITextField 的外观,则 UIBarButtomItem 色调颜色不起作用



我有一个UIBarButtonItem的实例。
我想将 UIBarButtonItem 的色调颜色更改为 OrangeColor。
我还在Appdelegate中将UITextField的外观更改为橙色。

// some view controller
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:nil action:nil];
[barButtonItem setTintColor:[KLStyle colorTitleOrangle]];

// Appdelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UITextField appearance] setTintColor:[UIColor orangeColor]];
}

如果我不评论[[UITextField appearance] setTintColor:[UIColor orangeColor]];,就会有问题,UIBarButtonItem 的色调颜色会出错。它仍然是默认色调颜色蓝色。

如果我评论它,UIBarButtonItem 的色调颜色将是正确的。

有人知道为什么会发生这种情况吗?

感谢您的帮助!

解决方法:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor lightGrayColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                              [UIColor colorWithRed:24.0/255 green:75.0/255 blue:152.0/255 alpha:1],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                                                              NSForegroundColorAttributeName,
                                                                                              nil]
                                                                                              forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                                                              NSForegroundColorAttributeName,
                                                                                              nil]
                                                                                       forState:UIControlStateDisabled];

最新更新