Constraints to center and object between two objects

喜你入骨 提交于 2019-12-04 01:28:06

There are a number of approaches:

  • In iOS 9, the easiest would be to define a vertical UIStackedView with a distribution of "equal spacing" and then addArrangedSubview the three circular subviews

  • Another option in iOS 9 would be to create two UILayoutGuide (which would represent the two question marks in your image), add them to the shared superview with addLayoutGuide and define them to be the same size as each other. The corresponding VFL might look like:

    "V:|[greenView1(==100)]-[layoutGuide1]-[redView(==50)]-[layoutGuide2(==layoutGuide1)]-[greenView2(==greenView1)]|"
    
  • In earlier iOS versions, rather than using UILayoutGuide, you could just create two "space" views (UIView with clear background so they're not visible) then define a constraint such that their heights are identical, and then define vertical spacing constraints between the five views (the three circles and the two spacer views) with a constant of zero.

    It might look like:

    I've made those "spacer" views visible, to illustrate the idea, but obviously you'd set them to be transparent so you can't see them in the UI.

    This is logically equivalent to the UILayoutGuide approach in iOS 9, except that the UIView "spacer" views just carry a little more overhead than a UILayoutGuide. But in iOS versions before 9, this is the common approach to this problem.

I've come up with easiest approach.

Just follow these steps :

  1. add a view between them the two circle
  2. add its trailing and leading space. (in my case zero to superview)
  3. add top and bottom space from the circles.
  4. now put your red circle in the recently added view
  5. make it horizontally and vertically center from Alrignment Menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!