我有一个UIBarButtonItem的实例 我想将UIBarButtonItem的tintColor更改为orangeColor 我还在Appdelegate中将UITextField的外观更改为orangeColor。
// 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的tintColor将出错。它仍然是默认的tintColor blue。
如果我发表评论,UIBarButtonItem的tintColor将是正确的。
有人知道为什么会这样吗?
感谢您的帮助!
答案 0 :(得分:0)
解决方法:
[[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];