Skip to content

基于SnapKit的封装,一行代码搞定一个View,不容易写错,或忘记约束

License

Notifications You must be signed in to change notification settings

Wejua/SwiftLayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  1. 一行代码解决视图布局,代码简短易读,写起来也快
  2. 解决经常写错布局的问题,错误的布局不会通过点语法提示出来
  3. 根据布局规律套用对应方法,降低忘记有关约束的概率,比如label设置了left和top,但是忘记了right和屏幕右边的间距,在label内容很长的时候就超出了屏幕右边

//nameLabel在self.view的里面(in)的上边,左边对齐,top偏离10,left偏离20

nameLabel.make.in.top(10).left(20).to(self.view)

//ageLabel在nameLabel的外面(out)的右边,基准线对齐,right偏离8, baseLine偏离1

ageLabel.make.out.right(8).baseLine(1).to(nameLabel)

//closeButton在self.view的外面(out)的右边,顶部对齐,right偏离20,top偏离16

closeButton.make.out.right(20).top(16).to(self.view)

//subView 在self.view的里面(in)中间,宽高为200,300

subView.make.in.center(width: 200, height: 300).to(self.view)

//contentView在self.view里面,top,left,bottom边距都为20, right边距约束不加

contentView.in.edges(.all(20, 20, 20, nil)).to(self.view)

//单加一条checkButton底部到self.view的底部的约束,间距为20,适用于增加一条底部约束撑起cell大小的时候

checkButton.make.in.edges(.bottom(20)).to(self.view)

About

基于SnapKit的封装,一行代码搞定一个View,不容易写错,或忘记约束

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published