【问题标题】:Can I change the background color of the Chromecast navigation bar?我可以更改 Chromecast 导航栏的背景颜色吗?
【发布时间】:2017-11-10 10:04:10
【问题描述】:

我已经查看了 GoogleCast v3 SDK 中可用的自定义样式,除非我遗漏了什么,否则我看不到更改 deviceChooser 的 backgroundColor 的方法。见下文:

有什么办法可以改变这种灰色吗?

【问题讨论】:

  • 你试过this answer吗?
  • 这是一个不受谷歌Chromecast SDK控制的导航控制器
  • 你能贴出你的代码吗??
  • 如果您不了解 Google Chromecast SDK,您将无法提供帮助。不过谢谢。
  • 还是没有运气?我也设法更改了取消按钮,但标题和背景似乎以某种方式固定

标签: ios swift chromecast


【解决方案1】:

有问题的导航栏样式并非来自 GoogleCast SDK(至少对于 iOS 15 上的 4.6.1 版动态),而是来自您自己应用的外观。更改导航栏的背景和标题文本颜色的一种方法(在 GoogleCast SDK 视图控制器上,但您自己的应用程序也是如此)是添加

UINavigationBar.appearance().backgroundColor = UIColor.darkGray
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]

在您的 AppDelegate 的 didFinishLaunchingWithOptions 函数中。 但是,无论我尝试为 UINavigationBar 或 UIBarButtonItem 外观设置什么色调颜色字段,我都无法更改取消按钮文本颜色。我也注意到我的应用程序中的行为,只有在情节提要中将色调设置为默认值的导航栏按钮会受到这种全局更改的影响,特别是通过设置

UIBarButtonItem.appearance().tintColor = UIColor.yellow

另一方面,如果您自己在情节提要中设置颜色,则上面的代码行不会更改它。这个结论让我相信这就是创建设备选择器视图控制器的方式,并明确设置了色调。

但是,我在主要问题的一个 cmets 中看到有人能够更改“取消”按钮的颜色(如屏幕截图所示),因此如果有人可以分享那段代码,我们将不胜感激.

谢谢!

编辑

当然,只有在发布此内容后,我才尝试从Reimond Hill 粘贴整个代码 sn-p,它可以更改取消按钮的颜色,特别是这个

GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor

我认为这在第一次不起作用的原因是我们正在设置连接控制器的导航属性,而不是设备控制器(它甚至没有这个属性)。所以我希望这会帮助其他人不要像我一样浪费时间。

【讨论】:

    【解决方案2】:

    您可以通过以下不同方式自定义 Chromecast SDK for iOS 的样式:

    GCKUIStyle.sharedInstance()
    

    我对导航栏样式的贡献:

    来自DOCUMENTATION我可以看到下图

    所有“样式类”的共同点是它们都继承自 GCKUIStyleAttributes 所以:

    func configureChromecast() {
        let gckCriteria = GCKDiscoveryCriteria(applicationID: "ABC123")
        let gckCastOptions = GCKCastOptions(discoveryCriteria: gckCriteria)
        
        GCKCastContext.setSharedInstanceWith(gckCastOptions)
        GCKLogger.sharedInstance().delegate = self
        
        // General
        let textColor: UIColor = UIColor.black
        let backgroundColor: UIColor = UIColor.white
        
        GCKUIStyle.sharedInstance().castViews.backgroundColor = backgroundColor
        
        GCKUIStyle.sharedInstance().castViews.headingTextColor = textColor
        GCKUIStyle.sharedInstance().castViews.headingTextFont = UIFont.textStyleRegular
        
        GCKUIStyle.sharedInstance().castViews.bodyTextColor = textColor
        GCKUIStyle.sharedInstance().castViews.bodyTextFont = UIFont.textStyleRegular
        
        GCKUIStyle.sharedInstance().castViews.captionTextColor = textColor
        GCKUIStyle.sharedInstance().castViews.captionTextFont = UIFont.textStyleRegular
        
        GCKUIStyle.sharedInstance().castViews.buttonTextColor = textColor
        GCKUIStyle.sharedInstance().castViews.buttonTextFont = UIFont.textStyleRegular
        
        GCKUIStyle.sharedInstance().castViews.iconTintColor = textColor
        
        
        // Navigation & Toolbar
        let navigationBackgroundColor: UIColor = UIColor.blue
        let navigationtintColor: UIColor = UIColor.white
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.backgroundColor = navigationBackgroundColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.backgroundColor = navigationBackgroundColor
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.headingTextColor = navigationtintColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.headingTextColor = navigationtintColor
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.bodyTextColor = navigationtintColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.bodyTextColor = navigationtintColor
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.captionTextColor = navigationtintColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.captionTextColor = navigationtintColor
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.buttonTextColor = navigationtintColor
        
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.iconTintColor = navigationtintColor
        GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.iconTintColor = navigationtintColor
        
        
        GCKUIStyle.sharedInstance().apply()
    }
    

    结果:

    【讨论】:

      【解决方案3】:

      根据文档,Google 不允许我们更改导航栏样式。所以我们可能需要在推送到 SDK 的媒体控制 UI 之前更改导航栏的外观。

      我在didFinishLaunchingWithOptions试过了

       [UINavigationBar appearance].barTintColor = [UIColor whiteColor];
       [UINavigationBar appearance].translucent = NO;
      

      希望对你有帮助:)

      【讨论】:

      • 一个很好的解决方案但并不理想,因为它必然会改变所有的导航栏。谷歌公开了大量用于蒙皮的 Cast 控件,他们应该添加导航栏。除非这是我们能做的最好的。
      【解决方案4】:

      您可以使用 GCKUIStyle 设置所有 GCK 视图的样式,

      例如:

      GCKUIStyle.sharedInstance().castViews.mediaControl.miniController.buttonTextColor = .black
      
      GCKUIStyle.sharedInstance().apply()
      

      在你的情况下,导航可以用这一行来设置样式

      connectionController.navigation.backgroundColor = UIColor.black
      

      查看此网址了解更多信息:

      https://developers.google.com/cast/docs/ios_sender/customize_ui

      【讨论】:

      • 这道题是关于backgroundColor的,buttontextColor和backgroundColor有很大的区别。
      • 代码只是您如何使用 GCKUIStyle 的一个示例,在 developers.google.com 上有对 GCKUIStyle 自定义的参考...
      • 现在为背景颜色编辑。干杯!
      • 对不起,我想你不明白最初的问题。使用您的代码行,您只能设置导航控制器的背景颜色。仍然没有办法用 GCKUIStyle 设置导航栏的背景色。导航栏中心的(标题)文本标签的文本颜色也是如此。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 2014-07-30
      • 2017-04-30
      • 2019-04-28
      相关资源
      最近更新 更多