CNContactPickerViewcontroller 导航栏颜色 [英] CNContactPickerViewcontroller navigationBar color

查看:65
本文介绍了CNContactPickerViewcontroller 导航栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how do i change the black bar to another color?

注意,这是一个 CNContactPickerViewcontroller...第一个屏幕(联系人列表)看起来不错,但是当我单击联系人以选择特定的联系人属性时,导航栏会变黑.

N.B this is a CNContactPickerViewcontroller...the first screen(list of contacts) looks fine but when i click on a contact to choose a specific contact property then the navigation bar turns black.

谢谢

推荐答案

一种方法是将UINavigationBar的Appearance设置成你想要的颜色:

One way is to set the Appearance of UINavigationBar to the color you want:

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

并且一旦您返回到之前的 ViewController(可能带有 -(void)viewWillAppear:(BOOL)animated),您将再次将其设置为您之前使用的颜色.

And once you return to the previous ViewController (Maybe with -(void)viewWillAppear:(BOOL)animated) you set it again to the previous color you were using.

我以这种方式展示了联系人:

I presented the Contact this way:

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 就会被调用,你可以根据你的需要在那里添加颜色恢复:

Once the contactController is Dismissed the viewWillAppear is called and you can add there the color restore depending on your needs:

-(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]};

}

这篇关于CNContactPickerViewcontroller 导航栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆