BlackStar
BlackStar

Reputation: 21

WKInterfaceController, how to programmatically set "Spacing" & "Insets"

I looked at Apples' docs for their WKInterfaceController:

Insets: The amount of space (in points) to insert between the edges of the interface controller and its content. Selecting Custom lets you specify different values for the top, bottom, left, and right edges.

Spacing: Additional spacing (in points) to include between items in the interface controller.

In the Interface.storyboard I am able to set these on the right panel, basically I set Insets to Custom and set them all to 0. For Spacing I check "Custom" and set it to 0 to also get rid of all the space

Is there a way to set these programmatically? I tried with code (I cant find the "Spacing" property for the WKInterfaceController, I wonder where this is coming from but I think for the Insets the corresponding property is "contentSafeAreaInsets" which takes a "UIEdgeInsets")

For the "contentSafeAreaInsets" it looks like its only a get only prop—error: "Cannot override with a stored property 'contentSafeAreaInsets'" when I tried:

override var contentSafeAreaInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

I also tried setting this in awake and even adding a override init but cant seem to be able to set this programmatically. Same goes for when I try for other stuff like when trying to set the "spacing" for WKInterfaceGroup (I cant even find a spacing definition other than it appearing in the right panel in the interface storyboard)

Are these just not meant to be set in code and must be set in the interface storyboard?

Upvotes: 0

Views: 169

Answers (1)

user3151675
user3151675

Reputation: 58149

Since contentSafeAreaInsets is a computed property, you should override it as such:

override var contentSafeAreaInsets: UIEdgeInsets {
     UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}

Upvotes: -1

Related Questions