SDAutoLayout的简单约束
首先在cocoapods导入SDAutoLayout第三方
pod 'SDAutoLayout', '~> 2.1.7'
在相对应的类里倒入头文件
#import <UIView+SDAutoLayout.h>
现在我要的效果图是这样的
先创建四个UIButton
fanxian1,fanxian2,fanxian3,fanxian3;
先写fanxian1的约束
//约束
self.fanxian1.sd_layout.
leftSpaceToView(self,kWidthScale(15)). // 距左其参照view之间的距离
widthIs(kWidthScale(170)). //视图的宽度
topSpaceToView(self,kWidthScale(290)). //距上其参照view之间的距离
heightIs(kWidthScale(55)). // 视图的高度
centerYEqualToView(self.fanxian2); //centerY与参照view相同
fanxian2的约束
self.fanxian2.sd_layout.
widthIs(kWidthScale(170)).
heightIs(kWidthScale(55)).
centerYEqualToView(self.fanxian1).
rightSpaceToView(self,10);
fanxian3的约束
self.fanxian3.sd_layout.
leftSpaceToView(self,kWidthScale(15)).
widthIs(kWidthScale(170)).
topSpaceToView(self.fanxian1,kWidthScale(10)).
heightIs(kWidthScale(55)).
centerYEqualToView(self.fanxian4);
fanxian4的约束
self.fanxian4.sd_layout.
widthIs(kWidthScale(170)).
heightIs(kWidthScale(55)).
centerYEqualToView(self.fanxian3).
rightSpaceToView(self,10);
最下面的小label的约束self.wenxinglabel.sd_layout.topSpaceToView(self.fanxian3,kWidthScale(10)).heightIs(10).widthIs(200);