【问题标题】:How to get rid of UIAppearance when not needed?不需要时如何摆脱 UIAppearance?
【发布时间】:2012-05-23 22:09:41
【问题描述】:

在我的 AppDelegate 中,我使用 UIAppearance 使用以下代码设置我自己的 NavigationBar:

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];

但我的应用程序的某些视图不需要它。我怎样才能摆脱它,所以我只能在相关视图中使用 IB?

【问题讨论】:

    标签: objective-c ios uinavigationbar uiappearance


    【解决方案1】:

    您不需要使用代理。只需获取实际的导航栏,它应该看起来不同并直接在其上设置颜色。

    [navigationBarInstance setTintColor:[UIColor blackColor]];
    [navigationBarInstance setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];
    

    您也可以将这两个值都设置为nil,您希望再次使用标准样式。 (由Ben Clayton 测试)。

    [navigationBarInstance setTintColor:nil];
    [navigationBarInstance setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    

    【讨论】:

    • 将背景图像和颜色设置为nil 确实将样式设置回默认值。经过测试。
    • 不适用于MFMailComposeViewController 实例(请参阅alpha.app.net/stuffmc/post/5028278
    • 所以你投了反对票?这是一个普遍的问题,而不是关于 mailcomposer..
    猜你喜欢
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多