[英]How to set Constraints in Xcode Using StoryBoard?
I am trying to set constraints in iphone devices using storyboard in xcode.我正在尝试使用 xcode 中的故事板在 iphone 设备中设置约束。 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?
但是我遇到了一些问题。我使用拖放放置了两个文本字段和两个按钮。一切都很好,除了一个按钮在 iphone 5s 中的宽度减少了,我不知道这背后的原因。有人可以帮忙吗?
Vandana, if the button width is reduced, it simply means that it does not have a fix width. Vandana,如果按钮宽度减小,则仅表示它没有固定宽度。 You have 2 options
你有2个选择
1) Set a width constraint on the button (eg I want it to be 300 points long) 1)在按钮上设置宽度约束(例如我希望它是 300 点长)
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. 2)设置前导和尾随约束(例如,在左侧,我希望与边框保持 10 点的距离,而在右侧,我希望与边框保持 10 点的距离。
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: 1) Option + 单击并按住“按钮” 2) 在情节提要上向左或向右拖动并在按钮上时释放:
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还
It would also help your question to add more info on how your constraints are setup.添加有关如何设置约束的更多信息也将有助于您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.