【问题标题】:iOS: Background image navigation bar mail compose view controlleriOS:背景图片导航栏邮件撰写视图控制器
【发布时间】:2012-09-14 09:43:15
【问题描述】:

从 iOS 5 开始,自定义UINavigationBar 的背景图像很容易,但是在为MFMailComposeViewController 设置背景图像时,我似乎缺少了一些东西。我使用下面的sn-p来设置MFMailComposeViewController的实例。

if ([MFMailComposeViewController canSendMail])) {
    // Initialization
    MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
    [vc setModalPresentationStyle:UIModalPresentationFormSheet];

    // Navigation Bar
    [[vc navigationBar] setBackgroundImage:[UIImage imageNamed:@"navbar_top"] forBarMetrics:UIBarMetricsDefault];

    // Configuration
    [vc setMailComposeDelegate:self];

    // Present Mail Compose View Controller
    [self presentViewController:vc animated:YES completion:nil];
}

虽然条形按钮项的外观正确,但邮件撰写视图控制器的导航栏却没有。我是否忽略了什么?

【问题讨论】:

    标签: ios ios5 uinavigationbar mfmailcomposeviewcontroller


    【解决方案1】:

    只需在“myAppDelegate.m”中添加一些代码,如下所示:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        ...
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"blueBarBG.png"] forBarMetrics:UIBarMetricsDefault];
        ...
    }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      编辑:参考custom-background-for-uinavigationbar链接。

      我想你可能输入了错误的图片名称:navbar_top 它可能是 navbar_top.png 或 navbar_top.jpg

      你可以试试这个:

      if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
      {
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_top.png"] forBarMetrics:UIBarMetricsDefault];
      }
      

      【讨论】:

      • 在当前情况下这不是一个选项,因为我不希望所有导航栏都具有相同的背景图像。我过去曾尝试过 [UINavigationBar 外观],这确实呈现了正确的结果,但是,正如我所说,我不能使用这种方法,因为并非所有导航栏都具有相同的背景图像。另外,由于我的目标是 iOS 5+,所以没有必要指定文件扩展名。
      • refer stackoverflow.com/questions/12017382/… 在 setBackgroundImage:image 中添加您的图片,而不是 nil
      【解决方案3】:

      你可以这样做是因为 MFMailComposeViewController 类继承自

      UINavigationController : UIViewController : UIResponder : NSObject
      

      但是请阅读苹果文档。苹果不允许这样做。

      重要

      邮件撰写界面本身不可自定义,并且不得由您的应用程序修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改会被忽略。因此,您必须在呈现界面之前设置内容字段的值。

      更多信息MFMailComposeViewController_class

      如果您仍想实施,那么这可能会对您有所帮助 changing-the-navigation-bar-with-MFMailComposeViewController

      【讨论】:

      • 如果对您有帮助,请告诉我。谢谢。
      • 我不确定这是否完全正确,因为使用 [UINavigationBar 外观] 自定义导航栏应用程序范围确实自定义了 MFMailComposeViewController 的导航栏背景。
      【解决方案4】:

      在你展示控制器之后

      // Present Mail Compose View Controller
      [self presentViewController:vc animated:YES completion:nil];
      

      像这样将图像添加为 imageView

      UIImage *image = [UIImage imageNamed: @"navbar_top.png"];
      UIImageView * iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,42)];
      iv.image = image;
      iv.contentMode = UIViewContentModeCenter;
      [[[vc viewControllers] lastObject] navigationItem].titleView = iv;
      [[vc navigationBar] sendSubviewToBack:iv];
      [iv release];
      

      但我相信 iOS4 提供了某种保护。

      这里明确说明,不得更改 Apple 提供的接口。

      http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

      重要提示:邮件撰写界面本身不可自定义,并且不得由您的应用程序修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改会被忽略。因此,您必须在呈现界面之前设置内容字段的值。

      我搜索了论坛,有些人的应用被拒绝了,所以我想你应该避免这样做。

      希望对您有所帮助。快乐编码:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多