george barlow
george barlow

Reputation: 125

How can I set a WatchKit app’s background color programmatically?

I was making a simple app with a slider and then I thought how can I change the background colour of the Apple Watch programatically. I know how you would normally do it for the iPhone but don't have a clue of what this one could be!

Upvotes: 2

Views: 4452

Answers (3)

M. Travis Volker
M. Travis Volker

Reputation: 2381

This question covers a lot of details that this question is asking (I've summarized below). How can I set the backgroundColor of a WKInterfaceController programatically?

  1. You cannot change the background of the watch face as of WatchKit 3. You can change the background color of a group control.
  2. Add a group to your WatchKit app.
  3. Create a corresponding outlet for your group and set the background color programatically like this ('self' may not be required in your context).

    Figure 1. setBackgroundColor

  4. Set the group's radius to '0' to removed the rounded corners that reveal the background color of the watch face

Figure 2. Radius Settings

  1. Set the Interface Controller's insets to '0' to remove the left and right edges that reveal the background color of the watch face

Figure 3. Insets

Upvotes: 1

zisoft
zisoft

Reputation: 23078

There is no API to change the color of a WKInterfaceController, you can set the color in InterfaceBuilder, but not in code.

Apple highly recommends to use the black color in Apple Watch Human Interface Guidelines:

Use black for your app’s background color. A black background blends seamlessly with the device bezel and maintains the illusion of no screen edges. Avoid bright background colors in your interface.

Upvotes: 4

Keshav
Keshav

Reputation: 1133

According to the apple developer documentation,you can follow the following syntax

func setBackgroundColor(_ color: UIColor?)

if you do not specify a custom background color or if you set the custom color to nil, the group uses the color assigned to the group object in your storyboard file. The default background color is clear.

Further,The solid background color to be displayed behind all items in the group. Specify nil to remove the custom color you previously set using this method.

Upvotes: 0

Related Questions