Custom UINavigationBar for MFMailComposeViewController - ios

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.

Related

UIActivityViewController: tint color of presented view controllers

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

How to change the background color of MFMailComposeViewController?

How to change the background color of MFMailComposeViewController?
I tried to add
mailController.view.backgroundColor = [UIColor redColor];
but the color is still white. Please help.
I started debugging the MFMailComposeViewController hierarchy. Heres my code.
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
[self presentViewController:mailComposeViewController animated:YES completion:^{
UIViewController* mailViewController = [mailComposeViewController.topViewController.childViewControllers firstObject];
UIView *mailView = [mailViewController.view.subviews firstObject];
CALayer *mailLayer = mailView.layer;
mailLayer.opacity = 0.5f;
UIView *backgroundView = [[UIView alloc] initWithFrame:mailView.bounds];
backgroundView.backgroundColor = [UIColor redColor];
[mailViewController.view insertSubview:backgroundView atIndex:0];
}];
What I found is that the MFMailComposeViewController which is a kind of UINavigationController has a top view controller which has a child view controller. The child view controller's view has a subview. This subview is where the content exists.
The issue is there are no subviews to this view. So I looked to see if it's layer has sublayers. It does not. By changing the layers alpha and adding a view with a background color behind this view we can clearly see this view is indeed the view we want.
After some searching around I found out that the mailLayer, which is a CALayerHost, can not only display contents from another process; it also allows user interaction to pass from the host app to the remote process. In other words, this class is the key to transmitting both user actions and graphics across process boundaries.
So I think this is a dead end. You won't be able to elegantly change the background color.

How To Change The Title Color of an MFMailComposeViewController?

I have in-app email using the MessageUI Framework. Everything works fine with the MFMailComposeViewController, but I want to change the title color from black to white. As of now, it looks like this:
I also want to change the bar button items to white. I was able to achieve all of this with all of my other views, but I simply don't know how to do this with an MFMailComposeViewController.
Set Title Text Attributes Of Navigation Bar in MFMailComposeViewController
MFMailComposeViewController *mailVc = [[MFMailComposeViewController alloc] init];
mailVc.mailComposeDelegate = self;
[[mailVc navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];

Why isn't the status bar adjusting the color of its text to match my UINavigationController?

I have an app that uses a navigation bar with a dark gray background color and a white title. According to this article, under "UINavigationController and the iOS7 Status Bar", it says that it should that as long as I am using a navigation controller, the status bar should automatically adjust its text color to match it. Here is a screenshot of the top of my app:
As you can see, the navigation controller's title was set to white, so shouldn't the status bar be set to white too? Here's my code for the navigation controller's color adjustment:
UINavigationController* navStack = [[UINavigationController alloc] initWithRootViewController:mainFeed];
navStack.navigationBar.barTintColor = [UIColor colorWithRed:20/255.0f green:20/255.0f blue:20/255.0f alpha:1.0f];
navStack.navigationBar.tintColor = [UIColor whiteColor];
[navStack.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
You need to add this in:
navStack.navigationBar.barStyle = UIBarStyleBlack;
What that article says is a bit misleading.

How to change UIWebview bottom toolbar color?

I have created a UIWebview in my app. I managed to change the background color of the navigation bar with setTintColor. However, I am unable to do the same for the bottom bar (with back/forward/refresh buttons). Can anyone help?
Did you create the bottom bar yourself? It probably is an UIToolbar:
UIToolbar *bottomToolbar = [[UIToolbar alloc] init];
bottomToolbar.tintColor = [UIColor redColor];

Resources