0

从 iOS 5 开始,自定义背景图像很容易UINavigationBar,但在设置背景图像时,我似乎缺少一些东西MFMailComposeViewController。我使用以下代码段来设置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];
}

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

4

4 回答 4

2

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

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

希望对你有帮助

于 2013-06-06T07:21:59.860 回答
0

You can do this because MFMailComposeViewController class inherited from

UINavigationController : UIViewController : UIResponder : NSObject

But go through the apple documentation. Apple wont allow to do so.

Important

The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.

FOR MORE INFORMATION MFMailComposeViewController_class

If you still want to implement then this might help you changing-the-navigation-bar-with-MFMailComposeViewController

于 2012-09-14T10:07:59.043 回答
0

编辑:参考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];
}
于 2012-09-14T09:53:25.043 回答
0

在你展示控制器之后

// 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

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

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

希望能帮助到你。快乐编码:)

于 2012-09-14T10:14:32.660 回答