以前工程里使用的都Masonry 适配的, 在工程中使用Layout比较少, 网上也很多关于SDAutoLayout 适配 的文章,在此以代码的形式介绍一下.
Dome代码:
UILabel *oneLable=[[UILabel alloc]init];
oneLable.backgroundColor=[UIColor redColor];
oneLable.text=@"SDAutoLayout适配oneLable";
oneLable.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:oneLable];
oneLable.sd_layout.topSpaceToView(self.view,kTopHeight+ 10).leftSpaceToView(self.view, 20).bottomSpaceToView(self.view, 10).widthIs(YHScreenWith-40);
UILabel *twoLable=[[UILabel alloc]init];
twoLable.backgroundColor=[UIColor greenColor];
twoLable.text=@"SDAutoLayout适配twoLable";
twoLable.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:twoLable];
twoLable.sd_layout
.topSpaceToView(self.view, kTopHeight+30)
.leftSpaceToView(self.view, 50)
.widthIs(300)
.heightIs(50);
UILabel *thirdLable=[[UILabel alloc]init];
thirdLable.backgroundColor=[UIColor greenColor];
thirdLable.text=@"thirdLable适配";
thirdLable.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:thirdLable];
thirdLable.sd_layout
.topSpaceToView(twoLable, 30)
.leftEqualToView(twoLable)
.widthIs(300)
.heightIs(50);
UILabel *forthLable=[[UILabel alloc]init];
forthLable.backgroundColor=[UIColor greenColor];
forthLable.text=@"forthLable适配";
forthLable.numberOfLines=0;
forthLable.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:forthLable];
forthLable.sd_layout
.topSpaceToView(thirdLable, 20)
.leftEqualToView(thirdLable)
.widthIs(100)
.heightIs(50);
UILabel *fiveLable=[[UILabel alloc]init];
fiveLable.backgroundColor=[UIColor greenColor];
fiveLable.text=@"fiveLable适配";
fiveLable.numberOfLines=0;
fiveLable.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:fiveLable];
fiveLable.sd_layout
.topEqualToView(forthLable)
.leftSpaceToView(forthLable, 30)
.widthIs(130)
.heightIs(60);
UILabel *sixLable=[[UILabel alloc]init];
sixLable.text=@"各类大师傅如果让";
sixLable.textAlignment= NSTextAlignmentCenter;
sixLable.textColor=[UIColor redColor];
sixLable.backgroundColor=[UIColor whiteColor];
[self.view addSubview:sixLable];
sixLable.sd_layout.topSpaceToView(fiveLable, 30)
.leftEqualToView(forthLable).offset(20)
.widthIs(300)
.heightIs(40);
UILabel *sevenLable=[[UILabel alloc]init];
sevenLable.text=@"sevenLable各类大师傅如果让";
sevenLable.numberOfLines=0;
sevenLable.textAlignment= NSTextAlignmentCenter;
sevenLable.textColor=[UIColor redColor];
sevenLable.backgroundColor=[UIColor whiteColor];
[self.view addSubview:sevenLable];
sevenLable.sd_layout
.topEqualToView(oneLable)
.leftEqualToView(sixLable)
.widthEqualToHeight(70);