[英]How to make view proportional between two views?
I want to achieve following layout我想实现以下布局
I am done with the circular oval views I have constrainted first and fourth oval view to start and end of superview.我已经完成了圆形椭圆形视图,我将第一个和第四个椭圆形视图限制为超级视图的开始和结束。 I am not able to understand how to make the horizontal line stretch its width between second and third view so that the horizontal line is equal widths between all the circular views?我无法理解如何使水平线在第二个和第三个视图之间拉伸其宽度,以便水平线在所有圆形视图之间的宽度相等?
I know I can take the oval views in the stack view but what about the horizontal line?我知道我可以在堆栈视图中获取椭圆视图,但是水平线呢?
For your problem in UIStackView
;对于您在UIStackView
中的问题;
There is 7
different UIView
as seperated CircularView
and SeparatorView
in the screenshot.截图中有7
不同UIView
作为单独的CircularView
和SeparatorView
。
Create a UIView
class for the Horizontal Line
and add a UIView
for set just SeparatorView
in horizontally centered
and in UIStackView set your HorizontalView's
portions as bigger in width
but same as height
with CircularView
.为Horizontal Line
创建UIView
class 并添加UIView
以仅在horizontally centered
设置SeparatorView
,在CircularView
中将HorizontalView's
部分设置为相同的height
,但width
更大。
Without UIStackView
;没有UIStackView
;
There's simple example with anchors.有一个简单的锚点示例。
var view1 = UIView()
view1.translatesAutoresizingMaskIntoConstraints = false
view1.backgroundColor = .gray
view1.layer.cornerRadius = 20
var view2 = UIView()
view2.translatesAutoresizingMaskIntoConstraints = false
view2.backgroundColor = .gray
view2.layer.cornerRadius = 20
var seperator1View = UIView()
seperator1View.translatesAutoresizingMaskIntoConstraints = false
seperator1View.backgroundColor = .lightGray
view.addSubview(view1)
view1.heightAnchor.constraint(equalToConstant: 40).isActive = true
view1.widthAnchor.constraint(equalToConstant: 40).isActive = true
view1.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
view1.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
view.addSubview(seperator1View)
seperator1View.leftAnchor.constraint(equalTo: view1.rightAnchor).isActive = true
seperator1View.centerYAnchor.constraint(equalTo: view1.centerYAnchor).isActive = true
seperator1View.heightAnchor.constraint(equalToConstant: 3).isActive = true
seperator1View.widthAnchor.constraint(equalToConstant: 20).isActive = true
view.addSubview(view2)
view2.heightAnchor.constraint(equalToConstant: 40).isActive = true
view2.widthAnchor.constraint(equalToConstant: 40).isActive = true
view2.centerYAnchor.constraint(equalTo: view1.centerYAnchor).isActive = true
view2.leftAnchor.constraint(equalTo: seperator1View.rightAnchor).isActive = true
There's output有output
So actually you can achieve this in many ways, in this approach you must calculate your all size of all kind of UIView
instances and it's widths
& heights
.所以实际上你可以通过多种方式实现这一点,在这种方法中,你必须计算所有类型的UIView
实例的所有大小及其widths
和heights
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.