今天介绍下用AutoLauout
实现等距约束
。
先看下效果图

nihao
创建一个带view的xib文件
在Attibute inspector 设置status bar为none ,size 为freeform 这里我只考虑竖屏,所以size classes我们选择 (高度设置成100吧)
//适配所有iphone竖屏
w:compact h:regular
创建我们需要4个UIButton和5个UIView(辅助视图,就是button之间的间距)
其中按钮我们是正方形w:75 ,这里需要等宽等高(宽和高都为75,定值),当屏幕变化的时候,不能改变按钮的大小,辅助view呢,为了满足按钮间的间距相等,所以五个view呢我们希望他们左右的约束为0,宽度始终相同。
给按钮添加约束

按钮等宽等高
给view设置等宽,再加一个高度

给view设置等宽
让他们的上下边距相等,左右边距为0

边距相等
最后在preview中查看个尺寸的效果

preview
7.效果出来后就把view设置成透明即可。
关于Size classes 和 AutoLayout 可以查考
- Size classes自悟 http://www.cocoachina.com/ios/20141217/10669.html
- Working with Constraints in Interface Builder https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraints/WorkingwithConstraints.html