Custom Setting MFMailComposeViewController open from UITextView

I have a simple UITextView with an email link. A text image is selected and detects links. That way you can click on the email and it opens using the MFMailComposeViewController view manager.

But, I do some settings when starting the application:

 [[UINavigationBar appearance] setBarTintColor: myGreyColor]; [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: myFont}]; [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 

Thus, all navigation panels are gray, with white text and white buttons, and the title has its own font.

My problem is that they all do not apply to the mail composer: the bar is gray and the title is white, but the default font is helvetica neue and the buttons are default. And the status bar is black, although my Info.plist says that UIStatusBarStyleLightContent and View controller-based status bar appearance set to NO .

I know how to configure MFMailComposeViewController when I call it manually, but here it appears automatically. How can I apply my styles to it?

+6
source share
3 answers

EDIT

Customizing the appearance of the MFMailComposeViewController is a very bad idea and will most likely reject your Apple application. The following solution should be used only if you are not going to send the application to Apple.


Looks like I solved it, thanks to Ray Wenderlich (again ..). Here is the complete code:

 - (void)viewDidLoad { [super viewDidLoad]; […] // Initializations // Link detection [_textView.attributedText addAttribute:NSLinkAttributeName value:@"mail://contact" range:[[content string] rangeOfString:@" contact@mymail.com "]]; _textView.delegate = self; } // Handle the link tap yourself - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { if ([[URL scheme] isEqualToString:@"mail"]) { MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init]; [mailVC setToRecipients:@[@" contact@ mymail.com"]]; [mailVC setSubject:@"About QuickReminder for iOS"]; mailVC.mailComposeDelegate = self; // Re-set the styling [mailVC.navigationBar setBarTintColor:myGreyColor]; [mailVC.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: myFont}]; [mailVC.navigationBar setTintColor:[UIColor whiteColor]]; [self presentViewController:mailVC animated:YES completion:^{ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; }]; return NO; } return YES; } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { // Notifies users about errors associated with the interface switch (result) { case MFMailComposeResultCancelled: NSLog(@"Result: canceled"); break; case MFMailComposeResultSaved: NSLog(@"Result: saved"); break; case MFMailComposeResultSent: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } break; case MFMailComposeResultFailed: NSLog(@"Result: failed"); break; default: NSLog(@"Result: not sent"); break; } [controller dismissViewControllerAnimated:YES completion:nil]; } 
+3
source

Then you should use the following appearance method instead of changing the entire application navigation bar: -

 [[UINavigationBar appearanceWhenContainedIn:<#(__unsafe_unretained Class<UIAppearanceContainer> *), ...#>, nil]setTintColor:[UIColor greenColor]]; 

Because your MFMailComposeViewController opens into your application, and you change the entire navigation bar of the application, therefore the reason for changing the navigation bar is MFMailComposeViewController. Using the aforementioned appearance method, you can change the selected classes or parent classes through which derived classes you can change. This will not change the MFMailComposeViewController, because it will not be part of your parent classes.

0
source

Swift 3:

 extension MFMailComposeViewController { override open func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent } open override func viewDidLoad() { super.viewDidLoad() navigationBar.isTranslucent = false navigationBar.isOpaque = false navigationBar.barTintColor = UIColor.white navigationBar.tintColor = UIColor.white } } 
0
source

All Articles