如何在ios 9中显示mfmessagecomposeviewcontroller中的导航栏颜色

时间:2015-11-02 13:23:42

标签: ios objective-c mfmessagecomposeview

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

我一直在使用这段代码。如果遗漏任何内容,请告诉我。

1 个答案:

答案 0 :(得分:4)

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

适用于MFMailComposeViewController。

4440

对于MFMessageComposeViewController

创建一个类似下面的方法来更改导航栏颜色。

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

        }

在初始化- (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]]; } 之前编写此方法。(这非常重要,否则无效)

此代码适用于ios 9。

可能会帮助你。