如何在ios7上将导航栏背景图像添加到MFMailComposeViewController

时间:2013-11-11 22:59:10

标签: ios iphone objective-c ios7 uinavigationbar

我正在使用MFMailComposeViewController。我无法将导航栏背景图像添加到ios7上的MFMailComposeViewController。我的代码工作ios7之前.But无法在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 

2 个答案:

答案 0 :(得分:0)

使用外观代理。以下代码将针对整个应用程序:

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

如果您希望仅在MFMailComposeViewController中定位,请更改第一行:

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

答案 1 :(得分:0)

如果您已经自定义了导航栏并且还希望它应用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];