简体   繁体   English

iOS自动布局:给顶部空间等于超级视图高度的1/5

[英]iOS Autolayout : Give top space equal to 1/5 of superview height

I want to set top space of my label to 1/5 of super view height. 我想将标签的顶部空间设置为超级视图高度的1/5。 I know we can do this at runtime by changing the constant to 1/5 of super view. 我知道我们可以在运行时通过将常量更改为超级视图的1/5来做到这一点。 But I want to do this using XIB only. 但是我只想使用XIB做到这一点。 Is there any way to achieve this? 有什么办法可以做到这一点?

Indeed @EI Captain, 确实,@ EI队长,

We need to use spacer view. 我们需要使用间隔视图。 @Mohammad, please have a look at constraints I have given to space view and label. @Mohammad,请查看我对空间视图和标签的限制。 it will definitely solve your issue. 它肯定会解决您的问题。

Attaching screen shot for you! 为您附加屏幕截图! enjoy. 请享用。

间隔视图

您的标签

A complicated way is to calculate the align to vertical center 一种复杂的方法是计算与垂直中心对齐 在此处输入图片说明

128 = (600 - 20) * 0.2 so we set 0.6 to the multiplier 128 =(600-20)* 0.2,因此我们将乘数设置为0.6

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

相关问题 将等宽视图添加到Superview-Autolayout iOS - Adding Views with Equal Width to Superview - Autolayout iOS iOS - 相对于 superView 的顶部空间 - iOS - relative top space to superView 如何设置自动布局约束,以使UIImageView的高度等于超级视图的高度? - How to set autolayout constraint so that the height of an UIImageView is equal to the height of the superview? 以编程方式使用自动布局的宽度和高度等于其超级视图? - Width and Height Equal to its superView using autolayout programmatically? 添加等于Superview高度倍数的垂直空间约束 - Adding vertical space constraint equal to superview height multiple 视图和超级视图自动布局的比例高度 - proportional height of view and superview autolayout 自动布局-使超级视图的高度等于子视图的高度+恒定,其中子视图为textView - Autolayout - Make superview height equal to subview height + constant where subview is textView ios uitableviewcell项目与superview故事板界面生成器的高度相等 - ios uitableviewcell item equal height to superview storyboard interface builder iOS自动布局:将尾随空格设置为等于超视图的宽度 - iOS Auto Layout: Set the trailing space equal to the width of the superview 基于屏幕(超级视图)高度的iOS顶部对齐约束 - iOS Top Alignment constraint based on screen (superview) height
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM