Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Title and Navigation bars white in iOS 11 on view using ABNewPersonViewController

I've inherited a legacy app and was tasked with updating it for iOS 11. In one view, the user can click on a name and add that user to their contacts. However, when going to the 'add contact' view in iOS 11, the navigation and status bars are showing up as white. It works fine on iOS 10 and below.

Here's a screenshot comparing iOS 10 (left) to iOS 11 (right):

iOS 10 vs 11 Note that this view is created programmatically, and not through the storyboard:

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);

I've tried a few different things based on what I found online:

  1. I found I can manually set the background color of the navigation bar, but that leaves the status bar white.
  2. I've tried adding a HeightConstraint to the new view. I confirmed the constraint is added, but it didn't help. However, I had to set the value with a constant (tried 0, 100, 1000 just for testing) and couldn't get the relative constraint working properly. Regardless, not sure if it was worth going down that path.
  3. I saw some articles online that iOS 11 changes how the status/nav bars work and recommended setting setContentInsetAdjustmentBehavior to NEVER. However, this looks like it only works on ScrollViews or TableViews. This contact add view appears just to be a UIView.
  4. Tried switching to CNContactViewController (as ABNewPersonViewController is deprecated), and ran into the same issue.

Any advice would be helpful.

Edit: The Navigation bar colors get set in the AppDelegate in the didFinishLaunchingWithOptions method as seen below. I tried removing all the custom logic that gets set here. This somewhat fixed the navigation bar, but the status bar was still white with white text.

-(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;
}
like image 678
Dave4988 Avatar asked Nov 14 '17 20:11

Dave4988


1 Answers

I also faced this kind of issue and i solved this by doing this.

  [[UINavigationBar appearance] setTranslucent:NO];
  [[UINavigationBar appearance] setBarTintColor: [UIColor redColor]];
  [[[[UIApplication sharedApplication] delegate] window] setBackgroundColor:[UIColor redColor]];

Hope this will help someone and save a lot of time :).

like image 72
Faizan Ali Avatar answered Oct 26 '22 20:10

Faizan Ali