How to change color of navigation bar in mfmessagecomposeviewcontroller while presenting it in ios 9

余生颓废 提交于 2020-01-03 17:16:08

问题


        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.


回答1:


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.



来源:https://stackoverflow.com/questions/33478646/how-to-change-color-of-navigation-bar-in-mfmessagecomposeviewcontroller-while-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!