I try to set up a view with AutoLayout constraints by using constraintEqualToAnchor()
:
override func viewDidLoad() {
super.viewDidLoad()
le
Here is example with if
statement modifying a StackView
and View
when a segmented clicked:
if (sender as AnyObject).selectedSegmentIndex == 0{
// Shrink the white view and stack view
heightConstraintView = containerView.heightAnchor.constraint(equalToConstant: 100)
heightConstraintView?.isActive = true
heightConstraintStackView = stackView.heightAnchor.constraint(equalToConstant: 100)
heightConstraintStackView?.isActive = true
} else {
// Before returning back the white view and stack view DEACTIVATE teh previous constraints
heightConstraintView?.isActive = false
heightConstraintStackView?.isActive = false
// Returning back the white view and stack view to normal size
heightConstraintView = containerView.heightAnchor.constraint(equalToConstant: 200)
heightConstraintView?.isActive = true
heightConstraintStackView = stackView.heightAnchor.constraint(equalToConstant: 200)
heightConstraintStackView?.isActive = true
}