4

無論我嘗試什麼,在用戶選擇通過電子郵件發送鏈接(它是MFMailComposeViewController)時出現的電子郵件屏幕中,按鈕始終是默認的藍色。如何從默認藍色爲MFMailComposeViewController製作UIBarButtonItems的顏色?

我有這個在我的AppDelegate:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.000 green:156/255.0 blue:51/255.0 alpha:1]]; 
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 
[[UINavigationBar appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor whiteColor] }]; 

而且它確實上色MFMailComposeViewController但沒有按鈕的標題。我如何實現這一目標?

當我在其他地方使用白色時,它也會使我的狀態欄變黑。

+0

可能重複http://stackoverflow.com/questions/19333855/change-navigation-button-color-in-mfmailcomposerviewcontroller-on-ios-7 ) – dlinsin

回答

15
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 
mailController.mailComposeDelegate = self; 
[mailController setToRecipients: [NSArray arrayWithObjects:@"recipients", nil]]; 
[mailController setSubject: @"Contact Us"]; 
[mailController setMessageBody: @"Mail Body" isHTML:NO]; 
[[mailController navigationBar] setTintColor: [UIColor blackColor]]; //color 
[self presentViewController: mailController animated:YES completion:^{ 
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent]; 
}]; 

由於iOS 6的,MFMailComposeViewController(和其他一些視圖控制器)是在一個單獨的進程中運行,因此它們不會在繼承應用程式使用的樣式。假設你使用的是最新的SDK,使用上述方法可能會有所幫助,至少可以在iOS 7上工作。 You can read more about remote view controllers here.

+0

嗯,任何想法爲什麼狀態欄仍然保持黑色?你的解決方案對於UIBarButtonItems來說非常合適。 –

+0

@DougSmith查看更新後的代碼,它可能會解決您的問題。 – Terry

+0

你不應該用M調用你的MailController,但是... – DjimOnDev

0

您可以在AppDelegate中爲您的UIBarButtonItems設置全局色調顏色,以便MFMailComposeViewController將其用作其自己的按鈕的顏色。

let barButtonItemAppearance = UIBarButtonItem.appearance() 
    barButtonItemAppearance.tintColor = KK.GRAPHICS.COLOR_WHITE 
[在MFMailComposerViewController更改導航按鈕顏色在iOS 7](的
相關問題