Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have horizontally aligned WKInterface elements fill view

I am trying to place 2 WKInterfaceButton items side by side on an Apple watch app. I have a WKInterfaceGroup which I set its layout to horizontal. This allows me to position the buttons next to each other. The issue is having them both fit exactly side by side and fill the screens width and auto adjusting regardless of watch size (38 or 42mm) . Currently I align one left the other right. Then to adjust the widths i have to manually adjust the widths until it looks correct. This seems a bit too hard coded as it doesn't allow for any future watch screen size changes.

What I need is a way to set a WKInterface element (in this case a button) to be half the available size of the watch. In a normal app you can use

 uiElementWidth = [UIScreen mainScreen].bounds.size.width/2

Is there an equivalent in WatchKit?

like image 705
RyanTCB Avatar asked Mar 15 '15 10:03

RyanTCB


2 Answers

You can rely on the storyboard to do this. Select the button and make its width to be relative to the container like the following:

enter image description here

like image 184
Ashraf Tawfeeq Avatar answered Oct 19 '22 16:10

Ashraf Tawfeeq


use Group as container and inside it align your buttons as left, center, right and Yah! use relative to container as told by Ashraf Tawfeeq enter image description here

like image 23
Rudra Avatar answered Oct 19 '22 16:10

Rudra