4
        MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc]init];
        [UINavigationBar appearance].barTintColor = [UIColor colorWithRed:0.0f/255.0f green:127.0f/255.0f blue:254.0f/255.0f alpha:1.0];
        [[messageController navigationBar] setTintColor: [UIColor whiteColor]];
        messageController.messageComposeDelegate = self;
        [messageController setBody:message];
        [messageController navigationBar].translucent =NO;                                             
        [messageController.navigationBar setBarTintColor:[UIColor colorWithRed:0.0f/255.0f green:127.0f/255.0f blue:254.0f/255.0f alpha:1.0]];
        // Present message view controller on screen
        [self presentViewController:messageController animated:YES completion:^{
        [messageController navigationBar].translucent = NO;
        }];

I have been using this code. Please let me know if anything is missing.

Ali Mumtaz
  • 41
  • 4
  • Please edit your post to make the code readable. Hint: indent each line by 4 spaces to form a code block. – Avi Nov 02 '15 at 13:25
  • Try moving the line which sets the tintColor to the completion handler of the presentation. – Avi Nov 02 '15 at 13:33
  • no change it is still coming white. – Ali Mumtaz Nov 02 '15 at 13:40
  • @Bhumica It is updating the navigation bar color and navigation bar text color on every other screen except MFMessageComposeViewController. – Ali Mumtaz Nov 03 '15 at 07:10
  • You have to call this method where you have called MFMessageComposeViewController not everywhere. In my code its working fine. –  Nov 03 '15 at 07:16
  • I have called this method right before initializing MFMessageComposeViewController and it has changed all the navigation bar colors throughout the app except in MFMessageComposeViewController. – Ali Mumtaz Nov 03 '15 at 07:23
  • Where you are calling your MFMessageComposeViewController ?on viewdidload? –  Nov 03 '15 at 07:31
  • No in actionsheet delegate method. Strangely it is changing the text color everytime I change navigation tintcolor but not changing bartintcolor in any case so far. – Ali Mumtaz Nov 03 '15 at 07:36
  • go through you code in detail.You are doing something wrong.Its working in my app completely. –  Nov 03 '15 at 07:44
  • I am only using MFMessageComposeViewController here no where else. I am also very astonished that why it is not working. Despite it is changing the tintcolor but not bartint color. – Ali Mumtaz Nov 03 '15 at 07:53
  • write your whole code here. –  Nov 03 '15 at 08:22
  • This is the whole code. – Ali Mumtaz Nov 03 '15 at 20:38

2 Answers2

5

You just need to add two lines to change navigation bar color.

For MFMailComposeViewController.

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];

[mc.navigationBar setTintColor:[UIColor whiteColor]];//cancel button will be of white color.
[mc.navigationBar setBarTintColor:[UIColor blackColor]];//bar color will be black.

if (mc != nil)
        {
            mc.mailComposeDelegate = self;
            [mc setSubject:emailTitle];
            [mc setMessageBody:bodyText isHTML:YES];
            [mc setToRecipients:toRecipents];

            [self presentViewController:mc animated:YES completion:nil];

        }

For MFMessageComposeViewController

Create one method like below for changing navigation bar color.

- (void)setNavBarColor:(UIColor *)navBarColor titleColor:(UIColor *)titleColor {
    [[UINavigationBar appearance] setBarTintColor:navBarColor];
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                          [UIFont fontWithName:@"Futura-Medium" size:17.0f],
                                                          UITextAttributeFont,
                                                          titleColor,
                                                          UITextAttributeTextColor,
                                                          nil]];
}

And write this method before you initialise MFMessageComposeViewController.(This is very important otherwise it will not work)

This code work for me in ios 9.

May be it will help you.

  • no the black color or any other color is not appearing in navigation bar. Tried this too. – Ali Mumtaz Nov 02 '15 at 14:04
  • I am using mfmessagecomposeviewcontroller. Tried in that. – Ali Mumtaz Nov 02 '15 at 14:04
  • It doesn't work for me, either, with MFMessageComposeViewController. – Avi Nov 02 '15 at 14:05
  • Verified that it *does* work for MFMailComposeViewController. Wonder why their implementations are so different as to make this code only work for one. – Avi Nov 02 '15 at 14:10
  • It is not working for MFMailComposeViewController for me. – Ali Mumtaz Nov 02 '15 at 14:16
  • MfMessageCompose... works properly. Do not forget as mentioned above :- "And write this method before you initialize MFMessageComposeViewController.(This is very important otherwise it will not work)". – SHS Jun 18 '19 at 06:58
0

I tried the edit with the solution mentioned up above and it didn't quite work. However, I found a solution with some help. My solution worked with a build target of iOS12.1+ and I tested it on iOS15.4:

MFMessageComposeViewController *messageController = [MFMessageComposeViewController new];
[messageController.navigationBar setBarTintColor: [UIColor redColor]];
[self presentViewController:messageController animated:true completion:nil];
[UIView appearanceWhenContainedInInstancesOfClasses:[NSArray arrayWithObject:[MFMessageComposeViewController class]]].tintColor = [UIColor redColor];

MFMessageComposeViewController: Cannot Style "Cancel" Button in Dark Mode

Eli017
  • 31
  • 7