MFMailComposeViewController自定义

时间:2013-06-05 08:05:16

标签: ios email mfmailcomposeviewcontroller

我正在自定义MFMailComposeViewController它在ios 5.0和ios 5.1中工作正常但在ios 6中无法正常工作。自定义发送和取消按钮不会出现在mailcontroller中。

我的代码是:

sendBtn = mailer.navigationBar.topItem.rightBarButtonItem;
cancelBtn = mailer.navigationBar.topItem.leftBarButtonItem;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];

UINavigationItem *mailVCNavItem = [mailer.navigationBar.items objectAtIndex:0];

        // Get the old bar button item to fetch the action and target.
UIBarButtonItem *oldCancelBarButton = [mailVCNavItem leftBarButtonItem];

        // Create your new custom bar button item.
        // In my case I have UIButton with image set as a custom view within a bar button item.
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"cancel-button-hover.png"] forState:UIControlStateNormal];
[backButton addTarget:oldCancelBarButton.target action:oldCancelBarButton.action forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0, 0, 55, 28)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

UIButton *sendbtn = [UIButton buttonWithType:UIButtonTypeCustom];
[sendbtn setImage:[UIImage imageNamed:@"send-btnComment.png"] forState:UIControlStateNormal];
[sendbtn addTarget:self action:@selector(sendMail:) forControlEvents:UIControlEventTouchUpInside];
[sendbtn setFrame:CGRectMake(0, 0, 55, 28)];
self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:sendbtn];

1 个答案:

答案 0 :(得分:1)

MFMailComposeViewController以及相关的Facebook和Twitter共享视​​图是通过iOS 6中的远程视图控制器实现的。这意味着控制器在另一个进程中运行,不再可以通过访问其属性来自定义它们。直接的子视图。您仍然可以通过UIAppearence执行此操作,但在iOS 6中无法再尝试更换按钮。