[英]Ios swift spacing between views and/or margins in percentage %
there is a way to set horizontal space between 2 view or between 1 view and one margin in percentage? 有没有一种方法可以在2个视图之间或1个视图和一个边距之间设置水平间隔百分比? I can set horizontal spacing or trailing space to superview or leading space to superview with constanst value (in pixels or some similar unit).
我可以使用固定值(以像素或类似单位)将水平间距或尾随空间设置为超级视图,或将前导空间设置为超级视图。
My personal solution was put a view A between what i want to pad (ie view B) and margin then i set view A width equals to superview and 0.3 (ie for 30%) at moltiplier. 我的个人解决方案是在我要填充的区域(即视图B)和边距之间放置一个视图A,然后将视图A的宽度设置为等于超级视图,并且在更宽的范围内设置为0.3(即30%)。
Each constraint in iOS has the following format iOS中的每个约束具有以下格式
item1.attribute1 = multiplier × item2.attribute2 + constant
item1.attribute1 =乘数×item2.attribute2 +常数
So, when you set eg spacing with constant value you define that constant
variable, and multiplier
is set to 1 (no sense). 因此,当您设置例如具有常数值的间距时,您将定义该
constant
变量,并将multiplier
设置为1(无意义)。
To set eg spacing in percentage you need to edit multiplier
value, let say to 0.3 for 30% (or could be 1.3). 要设置百分比间距,您需要编辑
multiplier
数值,比如说30%为0.3(或者可以为1.3)。 You can do it in Interface builder, just select you constraint and define multiplier value. 您可以在“界面”构建器中执行此操作,只需选择约束并定义乘数值即可。 (from document outline or directly from IB)
(来自文件大纲或直接来自IB)
Experiment with it, and also First/Second item. 尝试一下,也可以尝试第一项/第二项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.