MFMailComposeViewController customization in iOS7

ios, ios7, iphone, objective-c

Solution

You'll have to set the custom code directly on the `MFMailComposeViewController`. Here's an example from one of my apps:

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    // Fix UI -- Add your custom UI here
    [mailViewController.navigationBar setTintColor:[UIColor whiteColor]];
    [mailViewController.navigationBar setBarTintColor:[UIColor whiteColor]];
    // Set params
    [mailViewController setToRecipients:@[@"e-mail@email.com"]];
    [mailViewController setSubject:NSLocalizedString(@"Feedback", @"Feedback")];
    [self presentViewController:mailViewController animated:YES completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }];
}

EDIT: This is an iOS 7-only app, so also add needed checks so it doesn't crash on iOS 6

Problem

I'm having trouble customizing the MFMailComposeViewController in iOS7. I'm trying to hide and remove the title because i have a custom navigation appearance that i want to carry thorough into the mail view controller. I'm using this and it works fine on iOS6 but wont work the first time opening on iOS7. When I open the view and cancel the mail and then open the controller again it works on. The problem is the first time presenting the mail controller. Here is the code i'm using: ``` if ([MFMailComposeViewController canSendMail]) { UIView* parentView = [self showProgress]; MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = self; if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"CourierNewPS-BoldMT" size:1], UITextAttributeFont, [UIColor whiteColor],UITextAttributeTextColor, nil]]; [controller setToRecipients:[NSArray arrayWithObject:[LNController shared].profile.email]]; [controller setSubject:NSLocalizedString(@"APPSTORE_NAME", nil)]; NSData* energyData = [[self createEnergyCSVFile] dataUsingEncoding:NSUTF8StringEncoding]; NSData* timeData = [[self createTimeCSVFile] dataUsingEncoding:NSUTF8StringEncoding]; [controller addAttachmentData:energyData mimeType:@"text/csv" fileName:NSLocalizedString(@"ENERGY", nil)]; [controller addAttachmentData:timeData mimeType:@"text/csv" fileName:NSLocalizedString(@"TIME", nil)]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:@""]; [self presentViewController:controller animated:YES completion:nil]; [self hideProgress:parentView]; } ``` Anybody experience this before? Any help would be awesome.

Original source