I have an issue with auto layout constraints for UIView
inside the UIStackView
.
My goal is to create a view:
private static func makeSpace(with value: CGFloat) -> UIView {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = true
let heightConstraint = view.heightAnchor.constraint(lessThanOrEqualToConstant: value)
heightConstraint.priority = UILayoutPriorityDefaultHigh
NSLayoutConstraint.activate([
view.widthAnchor.constraint(equalToConstant: 295),
heightConstraint
])
return view
}
I want to add this as an arranged subview to UIStackView
as a space between other UIStackView
arranged subviews.
When I inspect these views by using visual inspector, my space view has height 0
. Although, when I change constraint to equalToConstant
, height is calculated properly.
I want to use lessThanOrEqualToConstant
to allow these spaces to shrink in case the screen layout is too small to fit them in proper size.
Has anyone else faced this problem?