Xcode swift view wrap content

You can use a trick with constraints to achieve wrap-content. For example :

let maximumWidth = frame / 4  //For example
yourView.widthAnchor.constraint(lessThanOrEqualToConstant: maximumWidth).isActive = true

The "maximumWidth" depends on your UI and your design and you can change it.

Also, you should set "lineBreakMode" in StoryBoard or in code like :

yourBtn.titleLabel?.lineBreakMode = .byCharWrapping //For UIButton or
yourTxt.textContainer.lineBreakMode = .byCharWrapping //For UITextView

01) How would I make my UILabel's height grow/shrink to match its contained text?

Just set top, left and right-constraint to the labels superview. Set the property number of lines to 0. Then it will start wrapping text.

02) How would I make my custom view's height grow/shrink to match its contained sub views?

By using interface builder this is much easier to achieve.

My suggestion to you is to start with your constraints in storyboard. You will not need to compile your code to see what the constraints will result in. Also you will get warnings and errors directly in the interface builder.

If you WANT to use programmatic constraints, my suggestion is to start using a framework for it. For example: https://github.com/SnapKit/SnapKit