【问题标题】:UIPopoverController Nav Bar AppearanceUIPopoverController 导航栏外观
【发布时间】:2012-09-15 19:12:51
【问题描述】:

我正在使用此代码在整个应用中自定义导航栏图像。

UIImage *navBarTexture = [[UIImage imageNamed:@"NavBarTexture_iPad"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearance] setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsLandscapePhone];

这很神奇。但是,当在 UIPopoverControllers 的导航栏上使用这个图像时,它看起来有点奇怪。我要使用它的默认 Apple 图像,我怎样才能让它保持原来的外观?

我知道我可以使用appearanceWhenContainedIn: 但是如果我将 nil 作为图像返回,我只会得到一个黑色空间。

【问题讨论】:

    标签: objective-c ipad uinavigationbar appearance


    【解决方案1】:

    我首先想到的是在自定义之前从导航栏中获取默认图像。我很震惊,它起作用了。

    UINavigationBar *appearanceProxBar = [UINavigationBar appearance];
    UIImage *defaultImage = [appearanceProxBar backgroundImageForBarMetrics:UIBarMetricsDefault];
    [appearanceProxBar setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBackgroundImage:defaultImage forBarMetrics:UIBarMetricsDefault];
    

    此外,正如您在答案中看到的那样,WWDC 2012 - 216 - iOS 上的高级外观自定义有一个巧妙的技巧,将外观代理转换为适当类的实例,以便编译器可以警告无法识别的选择器,并且代码完成也更精确。

    【讨论】:

    • 它不适用于 ios 6 中的 MFMailComposeViewController 类。有什么想法吗?
    • @rowwingman 它不起作用,因为MFMailComposeViewController 完全在不同的进程中呈现。
    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多