gpt4 book ai didi

iphone - 外观 API - UIBarButtonItem - MPMoviePlayerViewController 和 Youtube Webview

转载 作者:太空狗 更新时间:2023-10-30 03:36:55 25 4
gpt4 key购买 nike

我使用 Appearance API 设置了 UIBarButtonItem 的样式,如下所示

[[UIBarButtonItem appearance] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

这在整个应用程序中都非常有效。问题是,如果您在 uiwebview 中单击 YouTube 视频,这也会更改加载的 YouTube 视频的视频 View 中的按钮。

YouTube Examples

添加这样的代码:

[[UIBarButtonItem appearanceWhenContainedIn:[MPMoviePlayerViewController class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

不会改变任何东西(因为看起来 YouTube 的东西不仅仅是一个 MPMoviePlayerViewController

如果我没理解错的话,我也不能更改 YouTube View 的按钮(我也不希望这样)。

关于如何停止在此 YouTube 视频 View 上设置自定义栏按钮图像的任何想法?

如果您想仔细查看,这里是示例项目:https://dl.dropbox.com/u/80699/BarItemsSample.zip

最佳答案

因为你误解了 appearanceWhenContainedIn: 做什么。

SDK文档说:

To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, you use appearanceWhenContainedIn: to get the appearance proxy for the class.

下面的代码提供了您所需要的问题。请在你质疑我之前尝试一下。

例如,对于 iOS 5.x,您应该创建 UINavigationBar 的子类(不需要任何覆盖)

//In MJAppDelegate.h:
@interface MyNavigationBar : UINavigationBar
@end

//In MJAppDelegate.m:
@implementation MyNavigationBar
@end

然后你应该编辑你的 Storyboard,让它使用 MyNavigationBar 作为它的 UINavigationController 的导航栏。

最后,你可以使用下面的代码得到你想要的:

[[UIBarButtonItem  appearanceWhenContainedIn:[MyNavigationBar class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

对于 iOS 6,你可以只使用下面的代码:

[[UIBarButtonItem  appearanceWhenContainedIn:[UINavigationBar class], [UINavigationController class], nil] setBackgroundImage:barButtonBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

关于iphone - 外观 API - UIBarButtonItem - MPMoviePlayerViewController 和 Youtube Webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12290199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com