I have a custom navBar image in the navigation controllers in my app, set using UIAppearance protocol. However, when sending mail through the app (via MFMailComposeViewController), I want the default navBar instead of the custom one. I tried the approach outlined in this question: UIAppearance Remove Custom NavBar Background for UIPopoverController but it did not work. The code I used was:
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
But it had no effect whatsoever. My app is iOS 6+. Is this something specific to MFMailComposeViewController or am I missing something from this?
Edit: other approaches attempted:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
mailer.navigationBar.barStyle = UIBarStyleBlack;
[self.navigationController presentViewController:mailer animated:YES completion:nil];
[mailer.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Setting UIBarStyleBlack has some effect as the "Cancel" button subsequently turns black, but the background image is still set at the old value.
Try something like this:
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[mail.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
This should reset the background image for just this instance.
Remove custom background image
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
BEFORE calling,
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
Point is to set any customization for Navigation Bar appearance before init.
Related
I have multiple UINavigationController throughout my storyboard. Since I am using a tabbarcontroller every tab item has it's own UINavigationController embedded before it's ViewController.
I'd like to style all of these at the same time. Things that I have tried that work are going to a ViewControllers ViewWillAppear method and adding the following lines:
UINavigationBar *nav = self.navigationController.navigationBar;
nav.barStyle = UIBarStyleBlack;
nav.tintColor = [UIColor blackColor];
nav.translucent = NO;
But then I'd have to do this for every tab item and every ViewController.
Also, doing the following in the AppDelegate did NOT work:
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTranslucent:NO];
Specifically I am curious why using the appearance proxy doesn't work. I'm fairly new so if you give a solution involving custom UINavigationController or setting up a delegate please elaborate. Thanks!
Add this line too in your code:
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTitleTextAttributes: #{ NSForegroundColorAttributeName: navigationBarFontColor, NSFontAttributeName: navigationBarFont }];
I set all the button colors in my app via the above appearance proxy. It changes the color of the text for icons like "+" and back buttons like "< Home".
However, when I pop up a MFMailComposeViewController, the Cancel and Send button are in default iOS blue, and not in the color I've chosen like the rest of my application. Why is this?
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setSubject:REPORTMISSING_SUBJECT];
[mailController setToRecipients:[NSArray arrayWithObject:REPORTMISSING_RECEIPIENT]];
[self presentViewController:mailController animated:YES completion:nil];
}
As far as I know, the setTitleTextAttributes method can only change the title properties of the navigation bar and will not affect the buttons.
That said, if you still want to use this method to customize the title, try calling it right before creating your MFMailComposeViewController instance and it should work.
To change the cancel/send button colors you can use the tintColor property:
mailController.view.tintColor = navigationBarFontColor;
Or, you can use the appearance proxy for UIBarButtonItem. That should work too and will also let you change the font (again, you'll need to call it right before creating and presenting the mail composer):
[[UIBarButtonItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName: navigationBarFontColor, NSFontAttributeName: navigationBarFont } forState:UIControlStateNormal];
My app is showing iMessages ViewController via UIActivityController. However, the colors of labels are all messed up (blue so they are barely visible). I think this is because the view controller is using my app's tint color. See below.
How can i fix this?
thanks!
I ran into something similar with presenting MFMailComposerViewController modally. Try setting the appearance of your app's tint color to nil when presenting the activity controller, and then back to your desired app tint when it completes. Here's what I did with MFMailComposer. You should be able to modify for your activity controller:
...
[[UINavigationBar appearance] setBarTintColor:nil]; // Set to default before presenting
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
mailVC.mailComposeDelegate = self;
[self.navigationController presentViewController:mailVC animated:YES completion:nil];
...
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[UINavigationBar appearance] setBarTintColor:MyAppsCustomColor]; // set it back when finished
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
EDIT
When I use this solution, it changes the nav bar appearance in the presented modal that is selected in the activity view controller (messages, mail, etc). I'm setting my app's nav bar appearance to blue in my delegate, and then back to blue in the completion block. The app's nav bar remains blue, and the presented messages/mail modal is shown with the default light gray nav bar.
UIActivityViewController* avc =
[[UIActivityViewController alloc] initWithActivityItems:#[#""]
applicationActivities:nil];
avc.completionHandler = ^(NSString *activityType, BOOL completed) {
// ...
dispatch_async(dispatch_get_main_queue(), ^{
// Set tint color back to blue.
// This block is executed whether the user finishes or cancels.
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
[[self navigationController] setNeedsStatusBarAppearanceUpdate];
});
};
[[UINavigationBar appearance] setBarTintColor:nil];
[self presentViewController:avc animated:YES completion:nil];
I am using the UIActivityViewController to allow the user to send messages in my app. The issue is that when I choose Message as my share method, the "To:" section inherits the background color of my NavigationBar.
This is only a problem when you choose Message as your method - if you choose Mail, everything below the NavigationBar shows up with a white background.
Here is a screenshot of my issue:
In my AppDelegate.m I have the following code in didFinishLaunchingWithOptions:
[UINavigationBar appearance].barTintColor = [RMTheme theme].accentLight;
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
And the activity controller is triggered with the following code:
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
Well, I believe you are using "PUSH" style when you show your UIActivityViewController, instead you should use "Modal" style.
Storyboard
Code
[yournavigationController presentModalViewController:YourActivityViewController animated:YES];
Solution 2 - Use image
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"top_bar3"] forBarMetrics:UIBarMetricsDefault];
Solution 3 - Set bar tint
[[self navigationController]navigationBar].barTintColor = [UIColor whiteColor];
This question already has answers here:
MFMailComposeViewController in iOS 7 statusbar are black
(13 answers)
Closed 3 years ago.
I'm having an issue with the navigation Bar in MFMailComposeViewController.
I have an app where we set the "Status bar style" to "UIStatusBarStyleLightContent" in the plist file. It works perfectly in all views except when I call up MFMailComposeViewController. It goes back to black. The rest is ok. We have a custom image that does carry forward, and I can set the tint color with no problems. Any one know how to fix this? How to reset the "Status bar style" to "UIStatusBarStyleLightContent" in mail?
in AppDelegate
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"headerLogo.png"] forBarMetrics:UIBarMetricsDefault];
calling mail
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[[mailController navigationBar] setTintColor:[UIColor whiteColor]];
[[mailController navigationBar] setBarTintColor:[UIColor whiteColor]];
[self presentViewController:mailController animated:YES completion:nil];
I believe setting the barStyle in MFMailViewController is something that is not accessible unless because of private API in Apple's code. The reason why you're able to set the UINavigationBar to a certain picture in the app delegate is because in the app delegate, you are calling to the appearance of the UINavigationBar class instead of the tint color of the MFMailViewController's navigation bar.
Hope this helps
In the info.plist add new row:
UIViewControllerBasedStatusBarAppearance
Set it to:
NO
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[self presentViewController: mail animated: YES completion: ^ {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];