2012-06-12 48 views
13

我沒有問題在正常的viewController上改變導航主標題的顏色,但是在MFMailComposeViewController上,這是不可能的。 我可以改變按鈕的顏色(取消和發送),我可以設置導航欄的背景,但不能改變標題的顏色。我不想設定一個新的頭銜(顯然,它不是由蘋果允許的),我只是想改變顏色。「(更改MFMailComposeViewController中導航的主要標題顏色

請幫我 感謝

+0

請參閱此鏈接:http://stackoverflow.com/questions/1634417/changing-mfmailcomposeviewcontrollers-toolbar-color – Dee

回答

16
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
              [UIColor whiteColor],UITextAttributeTextColor, 
              [UIColor blackColor], UITextAttributeTextShadowColor, 
              [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil]; 

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes]; 

或者

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor]; 

希望它爲你工作..

10
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init]; 
    picker.mailComposeDelegate = self; 
    [[picker navigationBar] setTintColor:[UIColor blackColor]]; 
+0

這不是我搜索,在這裏你改變導航欄的顏色(我已經有一個背景),我想改變titleview – user1451163

+0

的顏色,但是要感謝必須嘗試^^ – user1451163

0

對於黑色以外的顏色,玩弄此代碼:

MFMailComposeViewController *mailController = [MFMailComposeViewController new]; 

      [mailController.navigationBar setTintColor:[UIColor colorWithHue:240.0f/359.0f 
                    saturation:85.0f/100.0f 
                    brightness:60.0f/100.0f 
                     alpha:0.0f]]; 
13

這是針對iOS 7,8,9的正確答案,和10:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]]; 

這是爲什麼:

校驗標記以上回答(通過馬尼)引用[UINavigationBar appearance]是不正確的,因爲它會改變UINavigationBar中標題的顏色,也會彈出MFMailComposeViewController,這是我不想要的效果。您需要像我的代碼那樣專門獲取選取器的NavBar。

設置tintColor在iOS 7(Mani的其他答案)中也是不正確的,因爲它設置按鈕的顏色,而不是標題。

此外,UITextAttributeTextColor現已棄用,請使用NSForegroundColorAttributeName

相關問題