簡體   English   中英

如何在iOS7上將Navigationbar背景圖像添加到MFMailComposeViewController

[英]How can I add navigationbar background image to MFMailComposeViewController on ios7

我正在使用MFMailComposeViewController。我無法在ios7上將navigationBar背景圖像添加到MFMailComposeViewController。我的代碼之前只能在ios7上運行,但是在ios7上不起作用。如何將導航欄背景圖像添加到ios7的MFMailComposeViewController?

    MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
    mailCompose.mailComposeDelegate = self;
    [mailCompose setSubject:@"SubjectName"];
    [mailCompose setMessageBody:shareBodyString isHTML:NO];
    if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
    {
      [self presentViewController:mailCompose animated:YES completion:nil];
    } 
    else {
         [self presentModalViewController:mailCompose animated:YES];
    }

    [mailCompose.topViewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault];  // working before ios7 

使用外觀代理。 以下代碼將針對整個應用程序:

UINavigationBar *navBar = [UINavigationBar appearance];
[navBar setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault];

如果您只希望在MFMailComposeViewController中定位,請使用以下命令更改第一行:

navBar = [UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil];

如果您已經自定義了導航欄,並且還希望它應用MFMailComposeViewController,則它僅允許使用UIAppearance代理來實現。 對於iOS 7.1.1,我替換了導航欄背景,但是無法更改狀態欄背景。 此外,它在以后的呼叫中將條形按鈕項目變為灰色。 因此,在創建MFMailComposeViewController之前,我停止自定義並嘗試返回默認的導航欄樣式

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setTintColor:nil];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica-Bold" size:18.0], NSFontAttributeName, nil]];

 MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM