Snapkit of Swift control constraints

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.