简体   繁体   中英

Constraints Not Working Properly

I have fiddled with the constraints for a while and for some reason on a view bigger than the view in the main storyboard looks awful. Right now it's on reset to suggested constraints. Those are my constraints below, I'm not sure what's going on. Is there something wrong with my Xcode or am I doing something wrong?

在此处输入图片说明

在此处输入图片说明

The button stretches because you pinned it to the top and to the bottom. So on a larger screen the distance from the top and the bottom stays the same which means that the button is stretched.

Keeping the size of the button

The keep the size of the bottom an center is vertically und horizontally you have to give a width and a height constraint and a centerY and centerX constraint:

在此处输入图片说明

Keeping the aspect ratio of the button

EDIT : This is a cleaner solution suggested by Sega-Zero :

To scale the button according to the screen size but keep its aspect ratio you have to set an equal width constraint (with a multiplier) between button an its superview, an aspect ratio constraint and centerY and centerX constraints:

在此处输入图片说明

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