如何将黑条更改为其他颜色?
N.B这是一个CNContactPickerView控制器......第一个屏幕(联系人列表)看起来很好但是当我点击一个联系人来选择一个特定的联系人属性时,导航栏就会变黑。
由于
答案 0 :(得分:3)
一种方法是将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]};
}
答案 1 :(得分:0)
我通过在延迟后更改导航栏子视图的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];