简体   繁体   English

Swift Autolayout:如何设置相同的距离约束

[英]Swift Autolayout: How to set same distance constraint

I want to set a constraint in my storyboard for my timer label (00:00) on the top and bottom.我想在故事板中为顶部和底部的计时器标签 (00:00) 设置约束。 These constraints should be the same on in lenght, so that my time label is always in the middle between the name label (timer 1) and the top of my prototype cell.这些约束在长度上应该是相同的,这样我的时间标签总是在名称标签(计时器 1)和原型单元顶部之间的中间。

在此处输入图片说明

I would be very happy to hear from you, best regrads!我很高兴收到你的来信,最好的毕业生!

Assuming that the position of "timer 1" is is properly constrained already, and does not depend on the position of "00:00"...假设“定时器1”的位置已经被适当约束,并且不依赖于“00:00”的位置......

You can put "00:00" into another UIView that acts as the container for "00:00".您可以将“00:00”放入另一个充当“00:00”容器的UIView中。 Add constraints to the container so that it is pinned on all four sides.向容器添加约束,使其固定在所有四个侧面。 Notably, its bottom side should be pinned to "timer 1".值得注意的是,它的底部应该固定在“定时器 1”上。 You can use this pop up for adding the constraints:您可以使用此弹出窗口添加约束:

在此处输入图片说明

Then, add center Y and center X constraints to "00:00":然后,将中心 Y 和中心 X 约束添加到“00:00”:

在此处输入图片说明

Since "00:00" is now in a view that spans the distance between the top of the cell and the top of "timer 1", setting its center Y to be the same as its container's center Y would mean that it is in the mid point between the top of the cell and the top of "timer 1".由于“00:00”现在位于跨越单元格顶部和“计时器 1”顶部之间距离的视图中,将其中心 Y 设置为其容器的中心 Y 将意味着它位于单元格顶部和“定时器 1”顶部之间的中点。

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

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