CNContactPickerViewcontroller navigationBar颜色

我如何将黑色条更改为另一种颜色?

注意这是一个CNContactPickerViewcontroller …第一个屏幕(联系人列表)看起来不错,但是当我点击一个联系人来select一个特定的联系人属性,然后导航栏变成黑色。

谢谢

在这里输入图像说明

一种方法是将UINavigationBar的外观设置为所需的颜色:

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]]; 

一旦你回到以前的ViewController(也许用-(void)viewWillAppear:(BOOL)animated ),你再次将它设置为你以前使用的颜色。

我以这种方式呈现了联系人:

 CNContactStore *store = [[CNContactStore alloc] init]; // Create contact CNMutableContact *contact = [[CNMutableContact alloc] init]; contact.givenName = @"Someone Name"; CNLabeledValue *contactPhoneNumber = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:@"Some number"]]; contact.phoneNumbers = @[contactPhoneNumber]; CNContactViewController *contactController = [CNContactViewController viewControllerForUnknownContact:contact]; contactController.navigationItem.title = @"Add to contacts"; contactController.contactStore = store; contactController.delegate = self; [[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]]; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]}; [self.navigationController pushViewController:contactController animated:YES]; 

一旦contactController被解除, viewWillAppear被调用,你可以在那里添加颜色还原取决于你的需要:

 -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]]; self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; 

}

我已经通过延迟更改navbar子视图的backgroundColor来解决这个问题,但并不美观,但对我来说这已经足够了:

 CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact]; vc.delegate = self; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (UIView *view in [vc.navigationController.navigationBar subviews]) { view.tintColor = [UIColor darkTextColor]; view.backgroundColor = [UIColor redColor]; } }); [self.navigationController pushViewController:vc animated:YES];