iOS7GM UINavigationBar 外观 setBackgroundImage:forBarMetrics:在 UIPopoverController 中不起作用

Posted

技术标签:

【中文标题】iOS7GM UINavigationBar 外观 setBackgroundImage:forBarMetrics:在 UIPopoverController 中不起作用【英文标题】:iOS7GM UINavigationBar appearance setBackgroundImage: forBarMetrics: not working in UIPopoverController 【发布时间】:2013-09-24 14:41:32 【问题描述】:

我在 ios7 gm 中使用 UINavigationBar 外观自定义 UINavigationBar BackgroundImage,但在 UIPopoverController 中不起作用。 我将此代码 sn-p 用于 iOS7 gm,

[[UINavigationBar appearance] setBackgroundImage:navigationBarBackgroundImage   forBarMetrics:UIBarMetricsDefault];

上面的代码是在AppDelegate中设置的

【问题讨论】:

【参考方案1】:

当导航控制器位于弹出框内时,其导航栏的外观设置为与弹出框的背景相匹配。

要自定义弹出框的背景,您应该使用自定义的UIPopoverBackgroundView 类。

【讨论】:

非常烦人的行为。在某些情况下,存在导致半透明失败的错误,导航栏变得透明。苹果,你怎么能发布这么可怕的操作系统?【参考方案2】:

由于setBackgroundImage:forBarMetrics: 不工作,而导航控制器包含在弹出框和setBackgroundColor: 工作良好,我们可以使用背景图像作为背景颜色的图案,如下所示用于某个导航栏:

[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"NavigationBarBG"]]];

或者对于所有导航栏:

[[UINavigationBar 外观] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"NavigationBarBG"]]];

【讨论】:

以上是关于iOS7GM UINavigationBar 外观 setBackgroundImage:forBarMetrics:在 UIPopoverController 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

自定义 UINavigationBar 外观以在 CNContactPickerViewController 中显示

在iOS 11中忽略设置UINavigationBar外观

UINavigationBar 外观 setBackgroundImage 隐藏状态栏

UINavigationbar 通过外观设置阴影不起作用

UINavigationBar 外观刷新?

为所有导航栏 (UINavigationBar) iOS 5.1+ 设置按钮和外观