iOS storyboard AutoLayout and adding constraint

℡╲_俬逩灬. 提交于 2019-12-31 02:12:30

问题


I am making changes to my app to support 3.5″ display. Currently it is supporting 4″ display. The screen layout looks like this. How to add following constraint in storyboard ? (I have enabled auto layout option in storyboard.)

  1. How to set button1 & button2 width to the half of super view's width ? and both should intersect at the middle of the superview's width.

  2. UIImage #1 should be placed at the middle of the superview's width.


回答1:


1 : Buttons

Didn't figure to do everything in interface builder

You've got to declare an NSLayoutConstraint outlet in your code :

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonWidthConstraint;

and then set :

self.buttonWidthConstraint.constant = self.containerView.frame.size.width /2;

Here is what you have to do in IB :

  • The 2 buttons must have the same width.

  • For both buttons, stick them to the left and right, and bottom, and fix their height like this :

2 : Center image view

Center the image view like this

Fix it's width, height, and Y position

Hope this helps.



来源:https://stackoverflow.com/questions/23884291/ios-storyboard-autolayout-and-adding-constraint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!