2

I have a very very simple stackView:

stackView.spacing = 10
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .fill
view.addSubview(stackView)
stackView.snp.makeConstraints { (make) in
    make.center.equalToSuperview()
}

Then I add three button to it:

stackView.addArrangedSubview(button1)
stackView.addArrangedSubview(button2)
stackView.addArrangedSubview(button3)

Things are great here.

enter image description here

I then hide the button1 and button 3, the stackView also layouts as expected.

enter image description here

enter image description here

But when I hide all subviews, then click the debug view hierarchy in the Xcode, the console start to spit out complaints.

enter image description here

I did not add any explicit constraints. There are constrains that are implicitly generated by UIStackView.

enter image description here

So anyone have any idea how to eliminate these autolayout warnings?

  • when the stackview doesn't have any subviews then that means the stacakview doesn't have any width/height constraint. It would just default it to a frame of `0` width and `0` height – mfaani May 13 '18 at 00:28

1 Answers1

-2

What's the sense of having UIStackView with zero subviews? If you want to hide all subviews, maybe it is better to hide the StackView itself? Anyway the only way to prevent appearing of these error messages for empty StackView is setting of width and height constraints for your StackView.

Serega
  • 630
  • 1
  • 4
  • 12
  • 1
    It make sense because button 1,2 and 3 are all possible to be set hidden or not hidden. (That's why I use stack view at first) So at one moment there are chances that all three buttons are set hidden. I tried to set min width and height constraint bu it does not work – user9474515 Mar 12 '18 at 04:54