【问题标题】:Remove Custom Nav Bar on Email Sheet删除电子邮件表上的自定义导航栏
【发布时间】:2013-08-07 00:55:59
【问题描述】:

我的 App Delegate 中有这段代码:

[[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 会包含什么内容?

【问题讨论】:

    标签: ios objective-c uinavigationbar mfmailcomposeviewcontroller


    【解决方案1】:

    我想通了!代码如下:

    [[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];
    }
    

    【讨论】:

    • 它对我不起作用.. 我的形象总是显示出来
    • @gbesler - 没问题。
    【解决方案2】:

    你可以试试这个:

    [UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil]
    

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

    来自文档:UIAppearance

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

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

    希望对您有所帮助。

    【讨论】:

    • 没用。这是我的代码:[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"Mail Nav.png"] forBarMetrics:UIBarMetricsDefault]; Mail Nav.png 是透明图像,所以它应该只显示正常的导航栏。
    • @Cody 我不认为您可以将其恢复为“正常”导航栏,正常栏在内部也在设置背景图像(或不确定的色调),因此一旦更改你不能恢复它。您必须从根本上复制它正在使用的背景图像。
    • 我认为这可能与appearanceWhenContainedIn: 有关。你知道MFMailComposeViewController 会包含什么吗?
    猜你喜欢
    • 2012-10-12
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    相关资源
    最近更新 更多