tongxing tongxing - 4 months ago 33
Swift Question

How to get the height constraint declared by snapkit for UIView?

For example, I declare some constraints through snapkit for a UIView:

timeProgress.snp_makeConstraints { (make) in
make.left.equalTo(startTime.snp_right).offset(15)
make.right.equalTo(endTime.snp_left).offset(-15)
make.height.equalTo(5)
make.centerY.equalTo(startTime)
}


How can I get the height constraint for the timeProgress?

Answer

You need to keep a global reference to the constraint.

let timeProgressHeightConstant = 5.0

timeProgress.snp_makeConstraints { (make) in
    make.left.equalTo(startTime.snp_right).offset(15)
    make.right.equalTo(endTime.snp_left).offset(-15)
    make.height.equalTo(timeProgressHeightConstant)
    make.centerY.equalTo(startTime)
}

Hence, you could now access self.timeProgressHeightConstant.