如何改变mfmessagecomposeviewcontroller中导航栏的颜色,同时在ios 9中显示

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

我一直在使用这个代码。 请让我知道是否有遗漏。

你只需要添加两行来改变导航栏的颜色。

对于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

创build一个像下面的方法来改变导航栏的颜色。

 - (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之前写下这个方法。 (这是非常重要的,否则将无法正常工作)

这段代码适用于ios 9。

可能会帮助你。