简体   繁体   中英

Xcode: How to constrain views of the same size to sit on top of each other

I have two views that represent the two sides of a card. So want one to sit exactly on top of the other. Is there are way of constraining this.

I trid selecting the first view, control dragging and selecting the second view and selecting constrain center horizontal and vertical but that doesn't seem to anything.

First, constrain their heights and widths to the same values. Next, select both views (using shift click) and choose align horizontal centers, as well as align vertical centers. This will mean they are at the same position and are the same size.

Also, you will need to constrain one of the views to the superview. Either pin it to center x and y, or do custom top and leading constraints.

Let me know if you have any questions.

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