默认情况下,我的邮件编辑器会选择它呈现视图控制器的背景图像。所以我有逻辑来禁用那个背景,它在模拟器中就像一个冠军,但在物理设备上却没有(或者至少在iPhone 4S上。两者都在使用iOS 8.1
- (void)composeEmail
{
if ([MFMailComposeViewController canSendMail])
{
self.mailComposer = [[MFMailComposeViewController alloc] init];
self.mailComposer.mailComposeDelegate = self;
// Disable navbar styling in presenting VC
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
NSString *emailTitle = @"Subject";
NSString *messageBody = @"Body";
//configure mail message
[self.mailComposer setSubject:emailTitle];
[self.mailComposer setMessageBody:messageBody isHTML:NO];
// Present mail view controller on screen
[self.callingController presentViewController:self.mailComposer animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];
}
} else {
// alert here
}
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Enable navbar styling in presenting VC
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"logo.png"] forBarMetrics:UIBarMetricsDefault];
// Close the Mail Interface
[self.callingController dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:1)
事实证明,解决方案既简单又不明显。修改UINavigationBar的命令必须在分配邮件编辑器之前完成。
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.mailComposer = [[MFMailComposeViewController alloc] init];
答案 1 :(得分:0)
代码中有两处更改:
在撰写电子邮件方式
中使用以下行[self.mailComposer.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
在didFinishWithResult方法中使用以下行。
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Happy-Rose-Day.png"] forBarMetrics:UIBarMetricsDefault];
我认为最后一点可能不需要,因为你的代码也在工作([UINavigationBar外观])