Search code examples
iosuiviewuikitinterface-builderxib

UIStackView as a root view of a XIB


I'd like to create a small UIViewController that contains an UITextField and a UILabel going one after the other.

I've decided to use an instance of UIStackView to lay out the subviews.

However, I have to add a UIStackView as a subview of the parent UIView in XIB.

Is it possible to configure XIB the way that the root view of the controller would be of a certain class, eliminating the need for the extra view?

I've attached the current view hierarchy. I'd like to get rid completely off the topmost View.

current view hierarhchy


Solution

  • Yes you can, you need just to set the stackview as the the root view of your view controller as following:

    enter image description here

    enter image description here