Change ios8 Extension Navigation Bar color - ios

I am working on iOS8 App Extension (Photo Editing Extension)
I have tried these method to update the Navigation Bar color, but failed:
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
It displays a default translucent gray nav bar.
Does anybody have idea on how to change the navigation bar color in iOS8 extension?

Try self.navigationController.navigationBar.barTintColor = UIColor.yellow first.
This should work for some host apps but not all. Because some host apps configure the colors in UIAppearance settings.
I found some info in here: https://pspdfkit.com/blog/2017/action-extension/#uiappearance
According to the link above, the extension will "picks up the UIAppearance settings from its host app" and this has a higher priority than the "setColor" message you send to the instance.
In this case what you can do is to modify the plist of the extension:
In NSExtension dictionary you can add a key NSExtensionOverridesHostUIAppearance and set value to YES. This will make your extension override the UIApprearance setting of the host app. Unfortunately this is only available in iOS 10 and later.
Hope you find it helpful.

Try setting the translucency of the UINavigationBar to NO like below, I believe then it should start picking up the colours
[[UINavigationBar appearance] setTranslucent:NO];
Here's the Apple Documentation for UINavigationBar translucent property

I have put your code in the appDelegate didFinishLaunchWithOption
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
return YES;
}
And works...

Related

Change tint color of buttons in activity sharing

My app uses a blueish color for the navigation bar. I set it globally in the AppDelegate like this:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.0 green:0.4705882353 blue:0.7450980392 alpha:1.0]];
The problem is that when the user shares a PDF file via email with a UIDocumentInteractionController, the 'Cancel' and 'Send' buttons are also close to blue, which makes them almost invisible.
I tried:
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:#[[UINavigationBar class]]] setTintColor:[UIColor whiteColor]];
and
[[UIButton appearanceWhenContainedInInstancesOfClasses:#[[UINavigationBar class]]] setTintColor:[UIColor whiteColor]];
This works everywhere else in my app, but not on screens presented from the UIDocumentInteractionController.
How can I change the colors of these buttons?
you need to set window tint color if you want to change color of bar button in UIDocumentInteractionController.
Add Below line of code after your code of Set NavigationBar tint color.
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.0 green:0.4705882353 blue:0.7450980392 alpha:1.0]];
// Add this line...
self.window.tintColor = [UIColor whiteColor];
This is working for me.
Note : if you want to reset window tint color use below delegate of UIDocumentInteractionController.
- (void)documentInteractionControllerDidDismissOpenInMenu:controller{
// restore the tintColor which you set # app delegate
self.appDelegate.window.tintColor = [UIColor redColor];
}
Hope this will help you.

In Objective C, while presenting a ViewController how to change the color of NavigationBar?

I am able to change tho color of NavigationBar by giving BackgroundColor but than I am not able change the color of StatusBar. Please provide a solution.
You should change the barTintColor instead of the background color.
[self.navigationController setBarTintColor:[UIColor redNavigationBarColor]];
Chances are that you will probably need to change also the barButton color and/or the the title color and all that should probably apply to more than one screen. So, to save you some time, if you want to globally change all these, put the code below in your app delegate
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
The code above will give you a red navigation bar with white title & buttons

Change 1Password App extension navigation bar title color

I am trying to change the color of navigation bar title and status bar items in 1Password App extension. I am unable to find a way to do it.
Please the image below.
There must be a way to do it, Uber app is doing it. Please find the image below.
Can some one please suggest me a way to do it.
change navigationBar title color:
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor grayColor]};
change status bar font color:
1.in the Info.plist add item: UIViewControllerBasedStatusBarAppearance NO
2.add the code in [viewController viewDidLoad]
tip:if you need change all viewController status font color,you should add in [AppDelegate application:didFinishLaunchingWithOptions:]
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Before presenting 1Password screen set the appearance as follows.
[[UINavigationBar appearance] setBarTintColor:nil];
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTitleTextAttributes: #{NSForegroundColorAttributeName:[UIColor blackColor]}];
In completion block of 1Password reset your appearance to your app sepecific appearance.

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

iOS 7.1 UINavigationbar and UIToolbar

After upgrading Xcode in iOS7.1 my navigation bar and UIToolbar buttons are not shown with correct colour.
When a view first appears the UIToolbar buttons all have the correct default blue colour and when I go to next page/view and come back to the previous view the toolbar buttons are shown in a grey colour.
I have tried to add the blue colour in viewDidLoad and viewWillAppear but no luck. Can someone please help me?
Thanks.
You can set up a theme for certain components all at once and they will be used throughout your application. In my app delegate I created a function when the application is initializing called setupTheme, and it does just that - sets up the "theme" of the application by saying things like [[UINavigationBar appearance] setBarTintColor:], which in effect sets the color of the navigation bar for ANY navigation controller throughout the app. Here's an example from an app that sets up some basic components that are reused so that any time you use them they will already have the correct theme applied.
- (void)setupTheme {
// get our theme colors
UIColor *primaryThemeColor = [UIColor blueColor];
UIColor *secondaryThemeColor = [UIColor whiteColor];
// nav bar
[[UINavigationBar appearance] setBarTintColor:primaryThemeColor];
[[UINavigationBar appearance] setTintColor:secondaryThemeColor];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:secondaryThemeColor}];
// tab bar
[[UITabBar appearance] setTintColor:primaryThemeColor];
// switches
[[UISwitch appearance] setOnTintColor:primaryThemeColor];
// search bar
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor blackColor]} forState:UIControlStateNormal];
}
Check out the iOS 7 transition guide for more details on specifics https://developer.apple.com/library/iOs/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1

Resources