2017-07-07 161 views
0

我有一個ContactPicker,可以控制項目中其他ViewControllers的顏色,但無法控制ContactsPickers 狀態欄的顏色。更改CNContactPickerViewController的狀態欄顏色

我的目標是讓狀態欄文本變成白色。

- (IBAction)btnSearch:(id)sender { 

    //global statusbar color 
    UINavigationBar.appearance.translucent = NO; 
    UINavigationBar.appearance.barStyle = UIBarStyleBlack; 

    CNContactPickerViewController *contactPicker = [CNContactPickerViewController new]; 

    //local statusbar color 
    contactPicker.navigationController.navigationBar.translucent = NO; 
    contactPicker.navigationController.navigationBar.barStyle = UIBarStyleBlack; 

    contactPicker.delegate = self; 

    contactPicker.displayedPropertyKeys = @[CNContactNamePrefixKey, CNContactPhoneNumbersKey]; 

    [self presentViewController:contactPicker animated:NO completion:nil]; 

} 

我也發現了這個在Xcode文檔: 應用程序默認使用新的基於控制器的視圖狀態欄管理系統。要退出此選項,請將UIViewControllerBasedStatusBarAppearance鍵的NO值添加到Info.plist中。

當我有一個全局屬性不控制每個視圖,我可以管理 讓ContactPicker狀態欄變成白色。

回答

1

我一直在嘗試各種方法,其並沒有爲我的 情況下工作:

(1) 在我的AppDelegate我想這一點,它沒有任何效果:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; 

(2) 在我的AppDelegate我有這個,但它沒有效果:

UINavigationBar.appearance.translucent = NO; 
UINavigationBar.appearance.barStyle = UIBarStyleBlack; 

(3) 就呈現ContactsController我有這個(無效果)前:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack; 
self.navigationController.navigationBar.translucent = NO; 

(4) 這也是剛剛呈現控制器之前沒有任何影響:

contactPicker.navigationController.navigationBar.translucent = NO; 
contactPicker.navigationController.navigationBar.barStyle = UIBarStyleBlack; 

(5) 這工作由exten丁類和重寫方法「preferredStatusBarStyle」:

注:在我的plist我設置了「查看基於控制器的狀態欄外觀」到「YES」

對於所有其他ViewControllers簡單設置半透明和NavigationCotroller barStyle UIBarStyleBlack工作,但 不是爲聯繫人。

.H

#import <ContactsUI/ContactsUI.h> 

@interface ContactViewController : CNContactPickerViewController 

@end 

.M

#import "ContactViewController.h" 

@interface ContactViewController() 

@end 

@implementation ContactViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

-(UIStatusBarStyle)preferredStatusBarStyle { 
    return UIStatusBarStyleLightContent; 
} 
@end