繁体   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