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

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):
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:
I found I can manually set the background color of the navigation bar, but that leaves the status bar white.
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.
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.
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;
}

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 :).

ABNewPersonViewController is deprecated in iOS 9. Use CNContactViewController instead.

Related

Coloured Status Bar on a TabBarController with NavigationBar not working

I've read a lot of posts on here and tried most of the options mentioned, but none fix the issue for me. I have an app that is based off of a Tab Bar Controller. Each tab is a UIViewController with a Navigation Bar at the top.
Adding this code to the AppDelegate gives me an orange coloured Navigation Bar with white text, but a white status bar with Black text.
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
Reading the answers on various pages suggest adding the following to the View controller:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Then calling this in View Did Load:
[self setNeedsStatusBarAppearanceUpdate];
This gets me a White status bar with White text, how can I now get the status bar to go orange to match my Navigation Bar??
The solution mentioned on here https://stackoverflow.com/a/19513714/505457 for those using a Navigation Controller doesn't work, I guess thats because my main controller is a Tab Bar Controller.
Anyone come across this before? Thanks in advance for any advice / suggestions you may have. I can provide a sample app if required, but its probably as quick to build one with the Tab Bar template, add a Navigation bar then paste in my code samples.
Plasma
You can find the statusBar UIVIew by it's name and tint it. Add this method to your AppDelegate.m and call it from didFinishLaunchingWithOptions:
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:#"statusBarWindow"] valueForKey:#"statusBar"];
if ([statusBar respondsToSelector:#selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[self setStatusBarBackgroundColor:[UIColor orangeColor]];
...
}
Note: There are apps in store that use this method. So it is okay with the apple HIG policy.
Well I had almost the same problem since IOS7 , But my quick solution is to change all your views from the first one, I am refering to set up your color bar configuration in the AppDelegate.m file, I recommend to use this free framework Nab Bar Color And Gradient is very easy to use and also you will be available to set a beautiful gradient on all of your views.
See the examples in the project.
Normally, you shouldn't be adding a UINavigationBar to a UIViewController. Instead, fill your UITabBarController will UINavigationControllers.
let firstViewController = FirstViewController(nibName: nil, bundle: nil)
let firstNavigationController = UINavigationController(rootViewController: firstViewController)
let secondViewController = SecondViewController(nibName: nil, bundle: nil)
let secondNavigationController = UINavigationController(rootViewController: secondViewController)
let navigationControllers = [
firstNavigationController,
secondNavigationController
]
yourTabBarController.setViewControllers(navigationControllers, animated: false)
The same general process applies if you are using storyboards.
Right so the point BSmith11 made about adding Navigation controllers to a Tab Bar got me thinking. So I did a bit of Googling and an answer on this page, helps a lot: Tab bar controller inside a uinavigationcontroller
By having the TabBar controller as the rootViewController, then inserting a "NavigationController" between that and the normal ViewController allows me to do this:
//Fix up the Navigation bar tint and set text colours to white
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
//Also requires setting 'View controller-based status bar appearance' to NO in .plist
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Which is exactly what I had before, and that gives me a coloured StatusBar and the exact same colour NavBar. Now to see if I can add it in to the existing app and not break everything.
Plasma

My Navigation Bar will not appear clear.

My navigation Bar will not appear clear. I have the code below in my viewdid load. This code works in other view controllers but for some reason this current view controller still shows a white translucent bar on top. Not sure why this would work on some pages and not others. The NSLog prints UIDeviceWhiteColorSpace 0 0, which I know means clear. There are bar buttons on the navigation bar and I need them to stay, or else I would of just completely hid that navigation bar. Any tips on why this would happen, or other ways to have a clear navigation bar. Thank you.
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
NSLog(#"color: %#", self.navigationController.view.backgroundColor);
NSLog(#"color: %#", self.navigationController.navigationBar.backgroundColor);
to apply a unified behavior to your UINavigationController allover the app, it is better to change its appearance once in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
....
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
[[UINavigationBar appearance] setTranslucent:YES];
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]];
...
}
The solution was putting the code into the viewWillAppear instead of viewDidLoad. Some view controllers need the navigation bar as full opacity and some needed it to be clear. Overall I got what I needed. Thank you!

Mail app segue (open-with) with incorrect navigation bar colors

I am currently attempting to open up the iOS mail all to create a draft with an attachment generated from my app. Here is a code snippet:
NSURL *fileLocation = [NSURL fileURLWithPath:self.site.dataFileLoc];
if(fileLocation) {
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
[self.documentController setDelegate:self];
[self.documentController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
}
However, what I am finding is that the navigation bar colours are completely off. In the AppDelegate, I am currently using these lines to set the global navigation bar appearance:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbarBackground"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[UIViewController class], nil] setShadowImage:[UIImage imageNamed:#"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
Unfortunately, the title of the mail view controller that appears is still black, despite my attempt to set the bar style to black (which should make the title white in return) and blue bar buttons. It does, however, seem to work fine for the "presentPreviewAnimated" view controller. How can I make the navigation bar of the mail view controller consistent?
Are there any nibs associated??
I usually try to avoid the desired level of UI customization (navigation bar styles, colors, custom background w/image) because drawing UI at runtime (unless dynamically required) generally gets me in trouble...
Why not mock it up in a .nib file and make use of the fancy-dance-y tools in Xcode?? Can be therapeutic to quickly obtain the desired grain of detail without having to hit run...

why Status bar and Navigation bar background colors are different in ios

I want to change background color of status bar and that background color should be same as navigation bar background color i.e dark gray color. My problem is after giving the same color for both status bar and navigation bar using my below code, i am getting the different color. I have already set UIViewControllerBasedStatusBarAppearance to NO. Please suggest me where i am doing wrong, i have attached below image for your reference.
here is my code of App delegate - didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//For changing status bar background color
self.window.backgroundColor = [UIColor darkGrayColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
//For changing navigation bar background color
[[UINavigationBar appearance] setBackgroundColor:[UIColor darkGrayColor]];
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
The reason they have different colors is because UIStatusBarStyleLightContent isn't the same color as [UIColor darkGrayColor].
If it's fine to adjust navigation bar color after how the status bar looks like, then you can set the status bar color:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Find out the RGB values of the status bar. (For example, I use DigitalColor Meter, it says it has R:28, G: 28, B: 28).
Then you can do something like:
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:1.0f]];
You might need to set translucency to NO.
If you only want it on certain screens, you can add this to the viewDidLoad method:
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:1.0f]];
First Change the statusBar style in your VC's viewDidLoad method
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
And then change the BarTintColor to your desired color in your VC's viewDidLoad method
[self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
In your AppDelegate's 'didFinishLaunchingWithOptions:' add following and it should work.
[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];

Buttons on navigation bar do not pick up window tint colour

Note, I've recently come back to this and it seems to have been fixed in more recent versions of the SDK, without me having to implement anything except the code in the question. Many thanks to all who answered.
I have an Objective-C app that runs on the iPad and displays a view controller with a modal presentation style of UIModalPresentationPageSheet:
UINavigationController *editorNavigationController = [[UINavigationController alloc] initWithRootViewController:editorViewController];
editorNavigationController.modalPresentationStyle = UIModalPresentationPageSheet;
[navigationController presentViewController:editorNavigationController animated:YES completion:nil];
When this view controller is displayed the buttons in the navigation bar are purple, which I assume has been picked up from the window's tint colour, which is what I want.
Later I need to display another view controller over the top, that fills the whole window:
UINavigationController *previewNavigationController = [[UINavigationController alloc]initWithRootViewController:myPreviewViewController];
[owningViewController presentViewController:previewNavigationController animated:YES completion:nil];
The problem I have is that when myPreviewController is displayed, the buttons in the navigation bar are grey. I've tried reinstating the colour on the new navigation controller:
previewNavigationController.navigationBar.tintColor = [UIColor colorWithRed:123/255.0 green:26/255.0 blue:69/255.0 alpha:1];
but without any joy.
How can I get the buttons to have the correct colour? Can I get the new navigation controller to pick up the window tint colour automatically, or do I have to set it explicitly? Is this something to do with presenting the second navigation controller over the top of one that uses UIModalPresentationPageSheet?
Any help much appreciated! Thanks,
Paul
You can set the navigationBar translucent and transparent.
In view Will Appear:
self.navigationController.navigationBar.translucent = NO;
Than create a UIView with frame size of navigationBar (CGRectMake(0,0,self.view.frame.size.height,22) and create buttons on it with color you need.
I know, thats a crutch but should work)
You can change the appearance of the UIBarButtonItem globally so all UINavigationControllers will share the same design:
[[UIBarButtonItem appearance] setTintColor:[UIColor purpleColor]];
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"fontName" size:16.0f],NSFontAttributeName,
nil] forState:UIControlStateNormal];
Additionally you could also change the [UINavigationBar appearance]:
//The setTintColor would tint the < Back button in the NavigationBar
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
#{NSForegroundColorAttributeName:[UIColor blueColor]}];
This code can be add it before presenting the UIViewControllers or simply in the AppDelegate.m.

Resources