简体   繁体   English

具有水平对齐的WKInterface元素填充视图

[英]Have horizontally aligned WKInterface elements fill view

I am trying to place 2 WKInterfaceButton items side by side on an Apple watch app. 我试图在Apple手表应用程序上并排放置2个WKInterfaceButton项目。 I have a WKInterfaceGroup which I set its layout to horizontal. 我有一个WKInterfaceGroup,我将其布局设置为水平。 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) . 问题是让它们完全并排放置并填充屏幕宽度并自动调节,无论手表大小(38或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. 我需要的是一种将WKInterface元素(在本例中为按钮)设置为手表可用尺寸的一半的方法。 In a normal app you can use 在普通的应用程序中,您可以使用

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

Is there an equivalent in WatchKit? WatchKit中有等价物吗?

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: 选择按钮并使其宽度相对于容器,如下所示:

在此输入图像描述

use Group as container and inside it align your buttons as left, center, right and Yah! 使用Group作为容器,在里面将你的按钮对齐为left,center,right和Yah! use relative to container as told by Ashraf Tawfeeq 根据Ashraf Tawfeeq的说法使用相对容器 在此输入图像描述

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

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