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?
value: CGFloat
to constraint... – Daumantas VersockasverticalCompressionResistance
of your view to 1000. This should make your spacing view shrink only when needed. You can also make the heightConstraint required instead of only high priority. – David Ganster