简体   繁体   中英

How to set Constraints in Xcode Using StoryBoard?

I am trying to set constraints in iphone devices using storyboard in xcode. But i am getting some issue.I have placed two textfields and two buttons using drag and drop.Everything is going fine except one button whose width get reduced in iphone 5s and i don't know the reason behind this.Can anybody help?

png

Vandana, if the button width is reduced, it simply means that it does not have a fix width. You have 2 options

1) Set a width constraint on the button (eg I want it to be 300 points long)

2) Set a leading and trailing constraint (eg on the left I want a fix 10 points distance from the bezel, and on the right I want a fix 10 points distance from the bezel.

I believe there's a warning in the storyboard, you just need to select the best option for you:

在此处输入图片说明

Ways to add a width constraint:

1) Option + click and hold "the button" 2) drag to the left or right on storyboard and release while it's on the button:

在此处输入图片说明

Some practical solutions:

  • add a "width" constraint for that button ( it can be >= also )

  • adde "equal widths" constraint for that button and another element

  • adde "trailing and leading" constraint for that button

also

  • try with different size classes to see your result.

It would also help your question to add more info on how your constraints are setup.

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