| Info | Value |
| --- | --- |
| Platform | e.g. ios/osx/tvos |
| Platform Version | e.g. 8.0 |
| SnapKit Version | e.g. 0.19.0 |
| Integration Method | e.g. carthage/cocoapods/manually |
such as
i make constraints on redView like this:
redView.snp_makeConstraints { (make) in
make.width.equalTo(100)
make.height.equalTo(100)
make.top.equalTo(view).offset(20)
make.left.equalTo(view).offset(20)
}
how can i get the constant of the constraints on readView?
var viewHeight: NSLayoutConstraint!
viewHeight.constant
You can always keep a reference to constraints from constraint:
var redViewWidthConstraint: Constraint?
redView.snp_makeConstraints { (make) in
redViewWidthConstraint = make.width.equalTo(100).constraint
}
Since a Constraint object has layoutConstraints: [LayoutConstraint], you can get any of its constraints' constants from its layoutConstraint properties.
In your case:
let widthConstant = redViewWidthConstraint?.layoutConstraints[0].constant
@Zsams I recommend @juliensaad's methodology, one thing to be careful with is the order in which the NSLayoutContraint's are installed is not guaranteed so you must take care to check attributes.
Because of that I highly recommend if you need this sort of check you make a Constraint from a single attribute make line such as:
widthConstraint = make.width.equalTo(100).constraint
heightConstraint = make.height.equalTo(100).constraint
This ensures the first object in the array is _always_ the right constraint.
Most helpful comment
You can always keep a reference to constraints from
constraint:Since a Constraint object has
layoutConstraints: [LayoutConstraint], you can get any of its constraints' constants from itslayoutConstraintproperties.In your case: