更改CNContactPickerViewController的状态栏颜色
问题描述:
我有一个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) 在我的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