简体   繁体   English

WatchKit 应用更改整个屏幕背景颜色

[英]WatchKit app change entire screen background color

I'm trying to change the entire background color of a WatchKit app using this:我正在尝试使用以下方法更改 WatchKit 应用程序的整个背景颜色:

self.group.setBackgroundColor(UIColor(red: 15/250, green: 121/250, blue: 205/250, alpha: 1.0))

The bottom and the top color, however, remain the default black.但是,底部和顶部颜色仍为默认黑色。 I set the interface controller insets left, right, top, and bottom to 0, and I also set the WKInterfaceGroup radius to zero.我将接口 controller insets left, right, top, and bottom 设置为 0,我还将WKInterfaceGroup半径设置为零。 What am I missing?我错过了什么?

截屏

There are a few possible problems you could be running into here. 您可能会在这里遇到一些可能的问题。

Glance Interface 一览界面

First off, if you are using a Glance Interface Controller, there will always be a black overlay at the bottom to account for the paging indicators. 首先,如果您使用的是Glance接口控制器,则底部总是会有一个黑色的覆盖层,以说明分页指示器。 You cannot get rid of this. 你不能摆脱这一点。

Groups 团体

If you are using a regular interface controller, then your group is not set up quite right. 如果您使用常规接口控制器,则您的组设置不正确。 It should be "Relative to Container" for both width and height with no other sibling groups. 宽度和高度都应为“相对于容器”,没有其他同级组。

Interface Controllers 接口控制器

The easiest way though to set the entire background color (minus the status bar of course) is to set the background color directly on the interface controller. 设置整个背景颜色(当然要减去状态栏)的最简单方法是直接在接口控制器上设置背景颜色。 That will result in an image that looks like the following. 这将导致图像如下所示。

界面背景色

Somewhere in those answers should be the solution to your issue. 这些答案中的某个地方应该是您问题的解决方案。

The only way to remove the top blank space is to switch the InterfaceController to Full Screen mode:删除顶部空白的唯一方法是将 InterfaceController 切换到全屏模式: 属性检查器中的界面控制器设置

To add a color background, I would use an old method, that comes from UIKit. The idea is to stretch 1x1 image for the entire screen.要添加彩色背景,我会使用来自 UIKit 的旧方法。这个想法是为整个屏幕拉伸 1x1 图像。

  1. Go to any graphic editor and create a whitePixel.png (or copy it right here): Go 到任何图形编辑器并创建一个 whitePixel.png(或将其复制到此处): 白色像素.png

  2. Add it to your project assets and don't forget to select Template rendering mode.将它添加到您的项目资产中,不要忘记 select模板渲染模式。 This will allow you to change color of the background without changing the asset.这将允许您在不更改资产的情况下更改背景颜色。

  3. Add an image to the controller. Set both width and height Relative to Container .将图像添加到 controller。设置相对于 Container的宽度和高度。 图像,相对于容器

  4. With image set to whitePixel , select any tint color.图像设置为whitePixel , select 任何色调。 Here's my settings:这是我的设置: WKInterfaceImage,属性检查器

And the result:结果:
具有纯色背景的 Apple Watch 屏幕

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM