2015-02-07 14 views
1

默認情況下,我的郵件編輯器會選取其呈現視圖控制器的背景圖像。所以,我有邏輯禁用此背景下,它的工作原理是在模擬器上而不是在物理設備上(或者在租賃iPhone 4S的一個冠軍,兩者都使用的是iOS 8.1代碼中的MFMailComposeViewController navigationBar覆蓋可以在模擬器中使用但不是設備

- (void)composeEmail 
{ 
if ([MFMailComposeViewController canSendMail]) 
{ 

     self.mailComposer = [[MFMailComposeViewController alloc] init]; 
     self.mailComposer.mailComposeDelegate = self; 

     // Disable navbar styling in presenting VC 
     [[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 


     NSString *emailTitle = @"Subject"; 
     NSString *messageBody = @"Body"; 

     //configure mail message 

     [self.mailComposer setSubject:emailTitle]; 
     [self.mailComposer setMessageBody:messageBody isHTML:NO]; 


     // Present mail view controller on screen 
     [self.callingController presentViewController:self.mailComposer animated:YES completion:^{ 
      [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

     }]; 
    } 
} else { 
    // alert here 
} 
} 

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail cancelled"); 
     break; 
    case MFMailComposeResultSaved: 
     NSLog(@"Mail saved"); 
     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail sent"); 
     break; 
    case MFMailComposeResultFailed: 
     NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
     break; 
    default: 
     break; 
} 

// Enable navbar styling in presenting VC 
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"logo.png"] forBarMetrics:UIBarMetricsDefault]; 

// Close the Mail Interface 
[self.callingController dismissViewControllerAnimated:YES completion:NULL]; 
} 
+0

什麼不行,請您詳細說明一下嗎? – gabbler 2015-02-07 03:14:19

回答

1

原來的解決方案既簡單和非顯而易見的。在分配郵件編輯器之前,必須先修改UINavigationBar命令。

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 
self.mailComposer = [[MFMailComposeViewController alloc] init]; 
0

兩個變化:

  1. 以下行使用在撰寫電子郵件方式

    [self.mailComposer.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 
    
  2. 使用下面的方法didFinishWithResult線。

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Happy-Rose-Day.png"] forBarMetrics:UIBarMetricsDefault]; 
    

我認爲,最後一點可能不是必需的,你的代碼也在努力([UINavigationBar的外觀])

相關問題