简体   繁体   中英

How to center a button above a tableview with the storyboard in swift?

I would like to get this result (storyboard view):

在此处输入图片说明

But when I simulate my app, I get this result (without any constraints)

在此处输入图片说明

So I tried to add some constraints to center the table view. But when I add any constrain, the TableView disappears. Why?

Remove all old constraint first and set constraint as shown in below images:

For Button:

在此处输入图片说明

For TableView:

在此处输入图片说明

Result:

在此处输入图片说明

As below, add two constraints is enough.

在此处输入图片说明

在此处输入图片说明

You should have 4 constraints for the button:
to the top
to the left (alternatively to the middle)
to the right (alternatively constant width)
constant height

And 4 to the tableview:
the top to the bottom of the button
to the left
to the right
to the bottom of the screen

Check out this tutorial if you dont understand autolayout: http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM