Auto-layout issue

2019-10-04 03:03发布

constraints

I have a view with two button. I have added auto-layout. But bottom space is more in iPhone 8 plus than iPhone 4s.I want to keep the spacing ratio of top and bottom same in all iPhone. How to fix it ?

iPhone 4s iPhone 8 plus

6条回答
The star\"
2楼-- · 2019-10-04 03:42

enter image description here

set constraints to bottom and leave top constraints

查看更多
劳资没心,怎么记你
3楼-- · 2019-10-04 03:45

Use Constraints like this. These buttons have bottom fix with superview.

User Constraints like this

查看更多
Explosion°爆炸
4楼-- · 2019-10-04 03:47

If you are using Auto layout then set constraint like this way

enter image description here

查看更多
神经病院院长
5楼-- · 2019-10-04 03:49

You should have 2 stack views. One Horizontal that contains the 2 buttons, and another vertical that contains the previous stack view. Set the horizontal stack view to "fill" and "equal spacing" and the vertical stack view to "fill" and "equal centering." Below I've included a couple of pictures to illustrate what I mean.

THE ONLY CONSTRAINTS ARE ON THE STACK VIEWS THAT BIND THEM TO THE SIZE OF THE CONTAINER VIEW, OR PARENT STACK VIEW.

This allows you to truly create an auto layout that scales with the device's screen size.

NestedStackViews

Properties of Stack View

enter image description here

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-10-04 03:58

1) Select both buttons

2) Click on "Resolve auto-layout issues" button on bottom and click on "Reset to selected Constraints"

enter image description here

查看更多
该账号已被封号
7楼-- · 2019-10-04 04:00

Updated

For Specific Ratio : To my understood, We can give Multiplier for Centre Vertically Constraints. Here ratio of top and bottom space will be same in all iPhone series. I gave Multiplier as 1.4

enter image description here

==================================

I know having several answers there. But, no one used UIStackView to add two simple buttons.

Drag two UIButton, select that two UIButtons, click Embed in Stack icon from here.

enter image description here

Stackview Properties

Give following things for UIStackView,

Set Axis as Horizontal, Distribution as Fill Equally, Spacing as 10 in Attributes Inspector

enter image description here

Stackview Constraints 1

Give constraints for that UIStackView, Check/Uncheck Margins, Left and Right = 0, Height as 30.

enter image description here

Stackview Constraints 2

Still, some constraints are not satisfied. Press Control and hold it, Click StackView and Drag to SuperView, you will get black pop up. Choose Center Vertically in container.

enter image description here

Stackview Constraints Customization

If you want to change height of UIButton or Bottom Space, click UIStackView and in Size Inspector, you can change height or move up/down.

enter image description here

查看更多
登录 后发表回答