2

我有圖像的自定義導航欄通用於所有views.Also自定義導航欄,我有一個觀點MFMailComposer是presented.But我沒有得到默認與發送的導航欄和取消按鈕嘗試這兒過得從navbar.But不working.This去除圖像是我的嘗試:如何顯示在MFMailcomposer查看默認的導航欄,而不是在IOS

-(void)mailShare:(id)sender{ 
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; 
Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 

    if (mailClass != nil) { 
     //[self displayMailComposerSheet]; 
     // We must always check whether the current device is configured for sending emails 
     if ([mailClass canSendMail]) 
     { 
      [self applyComposerInterfaceApperance]; 


     } 
     else 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Device not configured to send mail" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
      alert = nil; 
      return; 
     } 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Device not configured to send mail" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
     [alert show]; 
     alert = nil; 
     return; 
    } 

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 
    // [ picker.navigationBar setTintColor:[UIColor greenColor]]; 

    [picker setSubject:@"Try this Pack from FORCE PACKS"]; 


    CGRect rect = CGRectMake(0, 44, 320, 440); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [self.view.layer renderInContext:context]; 


    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 


    // Attach an image to the email 
    NSData *myData = UIImagePNGRepresentation(img); 
    [picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"]; 

    // Fill out the email body text 
    NSString *emailBody = @"I'm on the road to recovery! Check out my latest Exercise Log from FORCE Packs"; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentViewController:picker animated:YES completion:nil]; 

    myData = nil; 



} 
+0

您可以添加您用於定製導航欄的代碼嗎? –

+0

@Clever錯誤sure.this是代碼:[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@「navBar.png」] forBarMetrics:UIBarMetricsDefault]; –

回答

1

我有我的應用程序相同的問題。我已經刪除了使用UIAppearance協議設置導航欄圖像的代碼。相反,我在每個需要自定義導航欄的視圖控制器中爲UINavigationBar設置圖像。

我已經創建了一個UIViewController類與我在每一個的UIViewController -viewDidLoad調用自定義導航欄的方法。

在的UIViewController + Appearance.h

-(void)changeAppearance; 

在的UIViewController + Appearance.m

-(void)changeAppearance{ 
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed:@"Header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)] forBarMetrics:UIBarMetricsDefault]; 
    [self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeFont: [UIFont fontWithName:@"CooperBlack" size:18], UITextAttributeTextColor: [UIColor colorWithRed:57.0f/255.0f green:132.0f/225.0f blue:168.0f/225.0f alpha:1],UITextAttributeTextShadowColor: [UIColor clearColor]}]; 

    [self.navigationController.navigationBar setShadowImage:[[UIImage imageNamed:@"Header-shadow"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)]]; 

    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]]; 
} 

在您的視圖控制器.m文件首次進口UIViewController+Appearance.h並調用-changeAppearance方法在您的視圖控制器的-viewDidLoad像:

[self changeAppearance]; 

還刪除所有您正在使用自定義導航欄,如:[[UINavigationBar appearance] blahBlahBlah]

我希望這可以幫助。

0

我想通了!代碼如下:

[UINavigationBar appearance] setBackgroundImage:nil 
forBarMetrics:UIBarMetricsDefault]; MFMailComposeViewController 
*emailVC = [[MFMailComposeViewController alloc] init]; //the rest of the implementation goes here... [self presentViewController:emailVC 
animated:YES completion:nil]; Then, I set the nav bar appearance back 
to normal here: 

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
}