删除电子邮件工作表上的自定义导航栏



我的应用程序代理中有以下代码:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];

这很好,但我使用MFMailComposeViewController,并且希望它具有默认的NavigationBar外观。

我该怎么做?

编辑:

我试过这个代码:

[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], [UIViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"Textured Background.png"] forBarMetrics:UIBarMetricsDefault];

我也试过只使用这个代码。没有什么变化。默认导航栏,包括邮件视图控制器。

我想可能是appearanceWhenContainedIn:的问题。有人知道MFMailComposeViewController会包含在什么中吗?

我想通了!这是代码:

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
//the rest of the implementation goes here...
[self presentViewController:emailVC animated:YES completion:nil];

然后,我在这里将导航栏外观设置为正常:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
    [self dismissViewControllerAnimated:YES completion:nil];
}

你可以试试这个:

[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil]

这意味着MFMailComposeViewController类中包含的所有导航栏

来自文档:UIAppearance

这将返回外观代理,以便您可以这样修改它:

[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil] setBackgroundImage:myImage];

希望能有所帮助。

最新更新