我正在自定义 MFMailComposeViewController,它在 ios 5.0 和 ios 5.1 中工作正常,但在 ios 6 中无法正常工作。自定义发送和取消按钮不会出现在邮件控制器中。
我的代码是:
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];