在iOS 9中呈现时如何在mfmessagecomposeviewcontroller中更改导航栏的颜色 [英] How to change color of navigation bar in mfmessagecomposeviewcontroller while presenting it in ios 9

查看:145
本文介绍了在iOS 9中呈现时如何在mfmessagecomposeviewcontroller中更改导航栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        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.

推荐答案

您只需要添加两行即可更改导航栏的颜色.

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

用于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];

        }

对于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]];
}

并在初始化MFMessageComposeViewController之前编写此方法.(这非常重要,否则它将无法正常工作)

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

此代码在ios 9中对我有用.

This code work for me in ios 9.

也许会对您有帮助.

这篇关于在iOS 9中呈现时如何在mfmessagecomposeviewcontroller中更改导航栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆