简体   繁体   English

如何使两个视图之间的视图成比例?

[英]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作为单独的CircularViewSeparatorView

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实例的所有大小及其widthsheights

暂无
暂无

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

相关问题 如何在一个视图中制作两个集合视图? - How to make two collection views in one view? 如何在UISplitViewController的细节和主视图控制器之间刷新视图? - How to make the views refresh between detail & master view controllers of UISplitViewController? 如何使两个集合视图出现在同一个视图控制器上? - How to make two collection views appear on the same view controller? 如何在autolayout中使两个视图之间的距离变化 - How to make distance between two views variable in autolayout 在两个其他视图之间插入视图 - Inserting view between two other views 如何在不使用两个视图控制器的情况下为两个视图之间的过渡设置动画? - How to animate transition between two views without using two view controllers? 如何在自定义单元格中使UIImage的宽度等于视图的宽度和比例高度 - How to make UIImage width be equal to view's width and proportional height inside a custom cell 由于两个视图之间的高度相同,我如何决定哪个视图缩小/膨胀? - With equal heights constrain between two views, how do I decide which view shrinks/inflates? 如何在涉及选项卡栏,表格视图和导航控制器的两个视图之间进行筛选? - How to segue between two views involving a tab bar, table view and navigation controller? 如何通过根表视图控制器中的swift在两个表视图之间建立Segue连接? - How to establish Segue connection between two table views via swift in the root table view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM