spacingwatchkitapple-watchwkinterfacegroup

WKInterfaceGroup spacing not perfectly 0 sometimes (WatchKit)


I set up a group in my WatchApp Storyboard which has a width relative to container 1 and height relative to container 0.5. Inside this group I have 20 horizontal aligned groups with a width relative to container 0,05. The spacing of the group is set to 0 but when i set a background color to all groups I end up like this.

Group with groups

As you can see, some spacings are really zero but sometimes there is a small gap of about 1 px. Is this some sort of bug? Is it possibile to perfectly align the groups so that it looks like it is one solid background? Please don't tell me, that I can set the background color of the first group. Obviously I know that, i need it to work like this! Thanks!


Solution

  • I believe the problem is that the width of the screen isn't evenly divisible by 20. The width of the 42mm screen is 312 pixels, which divided by 20 is 15.6 pixels. Apple is probably truncating this to an integer value for performance, which results in the gaps.

    I reproduced your problem and then, to test my theory, I created 8 groups instead of 20 and set them to a width of 0.125. This resulted in no gaps, which makes sense since 312 is divisible by 8.

    The 32mm watch has a width of 272 pixels and, doing factorization of the two I got:

    272 = 2 * 2 * 2 * 2 * 17

    312 = 2 * 2 * 2 * 3 * 13

    Which shows that eight columns is the maximum by which you can evenly divide both sizes.

    If you have to have 20 columns, then I would set each to a fixed width, some at 15 and some at 16 pixels for the 42 mm, and 13/14 pixels for the 32 mm to get the layout you want.