UIActivityViewController: tint color of presented view controllers - ios

In an app I use white as the main tint color. If the user opens the UIActivityViewController, I set the tint color for the controller to the standard iOS blue. This works great for the activity view itself but when one wants to send a mail, the tint color is not blue but white again.
It would be great to have a way to set the tint color of the presented views. Is there one?
Opening a MFMailComposeViewController and setting the tint color to blue also has an effect on the displayed UIActionSheet, not so if the MFMailComposeViewController is opened from within an UIActivityViewController.
See screenshots for clarification: http://i.imgur.com/OggykJF.png
Edit: This is what I do for adding the tint color to the UIActivityViewController:
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
activityController.view.tintColor = [UIColor blueColor];
[self presentViewController:activityController animated:YES completion:nil];`

The best what you can do is to set window's tint color to system blue or any tint color you wish on UIActivityViewController just before you present it and then change window's tint color back to original just before you dismiss it. That will work. This is how I do it:
UIApplication.shared.keyWindow?.tintColor = Styles.color.systemBlue
and then
UIApplication.shared.keyWindow?.tintColor = Styles.color.tint

I had the same issue with the Cancel and Send buttons of the mail share controller being blue no matter what I tried. I found that tweaking the navbar appearance wasn't doing the trick. So I used this...
[[UIBarButtonItem appearance] setTintColor:tintColor];
I do this in an "Appearance" class I have that is called on load and sets all of the global appearances. For the navigation bar color, if you need to change that on the fly before presenting your share controller (UIActivityViewController), you can do it in the completion block when you first present your controller. For example:
[self presentViewController:[self _shareController] animated:YES completion:^{
[[UINavigationBar appearance] setBarTintColor:[UIColor yourNavBarColor]];
}];

I've not managed to get this to work at all, but have you considered the alternative - leaving the text white and changing the navbar background colour so they show up, e.g. with:
UINavigationBar.appearance().backgroundColor = .black
This seems to work for the buttons on the navbar for the Mail and Twitter sharing screens.

Set the tintColor on your UIActivityViewController after initializing but before presenting.
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
//Set the tint color on just the activity controller as needed here before presenting
[activityController.view setTintColor:[UIColor blueColor]];
[self presentViewController:activityController animated:YES completion:nil];

Related

Show transparent UINavigationbar will see black bar when swipe the viewController

I have a UINavigationController with 3 viewControllers. We know the three viewControllers share a common navigationBar.If I want to set the navigationBar totally transparent. I can put the code in viewWillAppear:
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setBarTintColor:[UIColor clearColor]];
self.navigationBar.translucent = YES;
and set it back in viewWillDisappear:
[self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self setShadowImage:nil];
[self setBarTintColor:THEME_COLOR];
self.translucent = NO;
I want to set the UINavigationBar translucent only in viewControllerB, so I put the code in viewControllerB. However, when I popToViewController B, I can see a black bar in the top right of the screen. Since the viewWillAppear is invocated. It seems can not be solved in my case.
I come out with some methods:
use different UINavigationBar.
use different UINavigationController. But UINavigationController can not push a new UINavigationController
Custom UIView like UINavigationBar.
I think above methos is more complicated。
Any ideas thanks!
That black color you see is the background color of main window. You can set background image or color to your main window from AppDelegate didFinishLaunchingWithOptions method (That's totally depends with your design of the view controller B) so that you won't see any difference.
Or else
Simply you can use viewDidAppear instead of using viewWillAppear, but that will have little flick though.

How to change the background color of navigation bar in a modal view?

I present a modal view when I click a cell in my custom tableview. How to change the background color of navigation bar in a modal view?
For example. I want to change it to black color.The following code do not work in the prepare segue method.
[destinationNavController.navigationBar setBackgroundColor:[UIColor blackColor]];
or
[[UINavigationBar appearance]setBackgroundColor:[UIColor blackColor]];
or
[destinationNavController.navigationBar setTintColor:[UIColor blackColor]];
in the viewDidLoad method of the destination Controller view I write
[self.navigationController.navigationBar setBackgroundColor:[UIColor blackColor]];
or
[[UINavigationBar appearance]setBackgroundColor:[UIColor blackColor]];
or
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];// only change the navigation item text color....
Any other ideas?
This the right way to present the modal controller and change the nav bar color, write the below code:-
[self presentModalViewController:customViewController animated:YES];
customViewController.topViewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
If you are on ios 7 or later, you need to use the barTintColor property of UINavigationBar.
Like this:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
I only tested this in iOS 11 so far and in my case our app is white but I want to present a fullscreen slide show with black color, but I still wanted a status bar, with white letters and the same black background as my main view
Step 1: make your view background color black.
XCode in your .xib or storyboard the parents view's background color black (very important step)
Step 2:
in your view controller that is in charge of this view, add this:
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
This makes the color of the status text to be white. This also works on iPhone X.

iOS 8.3 : Why is the navigation bar background color for MFMailComposeViewController still white?

Seems for iOS 8.3 the navigation bar background color for MFMailComposeViewController is white no matter what I do. How do I change the background color properly? Here is the code I am using. Simple and straight forward.
MFMailComposeViewController* myMailViewController = [[MFMailComposeViewController alloc] init];
myMailViewController.mailComposeDelegate = self;
[myMailViewController.navigationBar setBackgroundColor:[UIColor orangeColor]];
[self presentViewController:myMailViewController animated:YES completion:nil];
I tried many other alternatives such as changing the tint of the navigation bar, but I am getting the same result. Is this a bug? Any suggestions or tips is appreciated.
[UINavigationBar appearance].barTintColor = [UIColor yourColor];
This should be called before MFMailComposer instantiation.

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.

Custom UINavigationBar for MFMailComposeViewController

I have a UINavigationBar with an image for its tint to customize its appearance. However when I present the mail composer as a modal view the default UINavigationBar is displayed. Any suggestions how I can change that so that my custom bar is displayed?
You can access the navigation bar directly like so:
MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
viewController.navigationBar.tintColor = [UIColor blueColor]; ///< Or whatever colour you want to tint it / set the background image to, etc.

Resources