使用ABNewPersonViewController在iOS 11中使用白色标题和导航栏

Dav*_*988 8 objective-c ios ios11

我继承了一个遗留应用程序,并负责为iOS 11更新它.在一个视图中,用户可以单击一个名称并将该用户添加到他们的联系人.但是,当转到iOS 11中的"添加联系人"视图时,导航和状态栏显示为白色.它在iOS 10及更低版本上运行良好.

这是一个比较iOS 10(左)和iOS 11(右)的屏幕截图:

iOS 10 vs 11 请注意,此视图是以编程方式创建的,而不是通过故事板创建的:

ABRecordRef person = ABPersonCreate();
//...
ABNewPersonViewController *newPersonViewController = [[ABNewPersonViewController alloc] init];
[newPersonViewController setDisplayedPerson:person];
newPersonViewController.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
[self presentViewController:newNavigationController animated:YES completion:nil];
CFRelease(person);
Run Code Online (Sandbox Code Playgroud)

我根据在网上发现的内容尝试了一些不同的东西:

  1. 我发现我可以手动设置导航栏的背景颜色,但状态栏会保持白色.
  2. 我已经尝试将HeightConstraint添加到新视图中.我确认添加了约束,但它没有帮助.但是,我必须使用常量设置值(尝试0,100,1000仅用于测试)并且无法使相对约束正常工作.无论如何,不​​确定是否值得走这条路.
  3. 我在网上看到一些文章,iOS 11改变了状态/导航栏的工作方式,并建议将setContentInsetAdjustmentBehavior设置为NEVER.但是,这看起来只适用于ScrollViews或TableViews.此联系人添加视图似乎只是一个UIView.
  4. 尝试切换到CNContactViewController(不推荐使用ABNewPersonViewController),并遇到了同样的问题.

任何意见将是有益的.

编辑:导航栏颜色在didFinishLaunchingWithOptions方法的AppDelegate中设置,如下所示.我尝试删除在此处设置的所有自定义逻辑.这有点修复了导航栏,但状态栏仍然是白色的白色文本.

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

if ([MPUtils isIOS7OrHigher]) {
    [[UIToolbar appearance] setBarTintColor:[MPColors colorWithColorString:MPColorString0A3B77]];
    [[UINavigationBar appearance] setBarTintColor:[MPColors colorWithColorString:MPColorString0A3B77]];

    //color of text on buttons:
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];
} else {
    [[UIToolbar appearance] setTintColor:[MPColors colorWithColorString:MPColorString0A3B77]];
    [[UINavigationBar appearance] setTintColor:[MPColors colorWithColorString:MPColorString0A3B77]];
}

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

[MPUserDataSynchronizer syncUserData];

return YES;
}
Run Code Online (Sandbox Code Playgroud)

San*_*h R 0

ABNewPersonViewController在 iOS 9 中已弃用。请CNContactViewController改用。