A. Attach Snapkit at GitHub address: https://github.com/SnapKit/SnapKit
Official guidance Add constraint: Https://github.com/SnapKit/SnapKit#usage
Snapkit 3.0 Migration guide:https://github.com/snapkit/snapkit/blob/master/documentation/snapkit%203.0% 20migration%20guide.md
Second, the specific use
Swift 3.0 uses lazy loading
//AvatarLazy var Headerimageview:uiimageview ={Let Imgview:uiimageview=Uiimageview () Imgview.backgroundcolor=uicolor.redreturnImgview} () //titleLazy var Titlelabel:uilabel ={Let Time:uilabel=UILabel () Time.font= Uifont.boldsystemfont (ofsize: the) Time.Text="work notifications: IOS" returnTime } () //TimeLazy var Timelabel:uilabel ={Let Time:uilabel=UILabel () Time.font= Uifont.systemfont (ofsize:Ten) Time.textcolor=Uicolor.lightgray Time.Text="Yesterday"time.textalignment=. Right Time.baselineadjustment=. NonereturnTime } () //DescriptionLazy var Descriptionlabel:uilabel ={Let Time:uilabel=UILabel () Time.font= Uifont.systemfont (ofsize: -) Time.textcolor=Uicolor.lightgray Time.Text="[Time Clock] there are six minutes to go to work, ..."time.textalignment=. Left Time.baselineadjustment=. NonereturnTime } () //non-processing time 1Lazy var Nohandlelabel:uilabel ={Let Time:uilabel=UILabel () Time.ishidden=trueTime.backgroundcolor=. Red Time.font= Uifont.systemfont (ofsize:Ten) Time.textcolor=Uicolor.white Time.Text="1"time.textalignment=. Center Time.baselineadjustment=. NonereturnTime } ()
View Code
To add a constraint to a control by using Snapkit
Func addsubviews ()Void {self.addsubview (Self.headerimageview) Self.addsubview (Self.titlelabel) SELF.ADDSU Bview (Self.timelabel) Self.addsubview (Self.descriptionlabel) Self.addsubview (Self.nohandlelabel) //Avatarself.headerImageView.snp.makeConstraints {(make)inchMake.left.equalToSuperview (). Offset (Ten) Make.top.equalToSuperview (). Offset (Ten) Make.bottom.equalToSuperview (). Offset (-Ten) Make.width.equalTo (Self.headerImageView.snp.height)} //titleself.titleLabel.snp.makeConstraints {(make)inchmake.top.equalTo (Self.headerimageview) make.left.equalTo (self.headerImageView.snp.right). Offset (Ten) } //Timeself.timeLabel.snp.makeConstraints {(make)inch //make.top.equalTo (self.titleLabel.snp.top)make.bottom.equalTo (Self.titleLabel.snp.bottom) Make.right.equalToSuperview (). Offset (-Ten) } //Descriptionself.descriptionLabel.snp.makeConstraints {(make)inchMake.left.equalTo (self.titleLabel.snp.left). Offset (0) Make.bottom.equalTo (self.headerImageView.snp.bottom). Offset (0) Make.right.equalTo (Self.nohandlelabel). Offset (- -) } //Unhandled Eventself.noHandleLabel.snp.makeConstraints {(make)inchMake.right.equalTo (self.timeLabel.snp.right). Offset (0) Make.bottom.equalTo (self.descriptionLabel.snp.bottom). Offset (0) Make.top.equalTo (self.descriptionLabel.snp.top). Offset (0) Make.width.equalTo (self.noHandleLabel.snp.height). Offset (0) } }
View Code
:
Snapkit of Swift control constraints