2017-02-03 6 views
0

黒いバーを別の色に変更するにはどうすればよいですか?CNContactPickerViewcontroller navigationBar色

N.BこれはCNContactPickerViewcontrollerです。最初の画面(連絡先の一覧)はうまく見えますが、連絡先をクリックして特定の連絡先プロパティを選択すると、ナビゲーションバーが黒くなります。

おかげ

enter image description here

+0

私の答えはあなたを助けましたか?もしそうなら、それを正しいものとしてチェックしてください。ありがとう! –

答えて

3

一つの方法は、あなたが望む色にUINavigationBarの外観を設定することです:

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

そして、あなたは(たぶん-(void)viewWillAppear:(BOOL)animatedで)以前のViewControllerに戻る一度使用していた以前の色に再び設定します。

私は連絡先をこのように提示:

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

}

+0

これは試しましたか? – matt

+0

はい。それは私のために働いた –

+1

私の経験は、あなたのアプリの一部ではないので、この方法で2番目のCNContactPickerViewcontroller画面を制御することができないということです。 – matt

0

私は、遅延の後に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]; 
関連する問題