Search code examples
iosobjective-ciphoneipadmfmailcomposeviewcontroller

changing the MFMailComposeViewController navigationBar title font


I have a MFMailComposeViewController and when I've set the subject it also sets it as the subject. The question is how do I customize the font of the title and color?

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setSubject:@"Feedback for MyApp"];

Solution

  • i've changed the font generally for my apps from the app-delegate for all navigation bars of all view controllers. if you don't mind it changing all of your navigation bar title fonts, put something like the following in applicationDidFinishLaunching:withOptions:

        if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
            // set the navigation bar font to "courier-new bold 14"
            [[UINavigationBar appearance] setTitleTextAttributes:
             [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor,
                                                        [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], UITextAttributeTextShadowOffset,
                                                        [UIFont fontWithName:@"CourierNewPS-BoldMT" size:14.0], UITextAttributeFont, 
                                                        nil]];
    

    update: if you want it specific to this one case, you can probably use appearanceWhenContainedIn: using the arguments Alexander Akers suggested in the comment below, since UIViewController inherits from UIAppearanceContainer. i know appearanceWhenContainedIn: works in other cases such as UIBarButtonItems contained in UINavigationBar, so it should work similarly for this situation.