Why IB doesn't support auto resizing for the root view?

My root view in IB is perfectly constrained by its content views. It works fine during runtime. However, IB insists that it is not correctly constrained. It seems because root view's size is hard coded by IB and cannot adjust dynamically to fit its content. But why? It is really annoying. Should I file a radar?

Replies

What platform?


>> My root view in IB is perfectly constrained by its content views. It works fine during runtime.


Perfectly constrained in the sense of determined by the sizes of the content subviews (rather than the content subviews deriving their sizes from the root view)? In that case, you might have a conflict between the size determined by the subviews, and the size imposed on it by the device or window it's the root view of. (Hence the question about which platform. On the Mac, the root view can cause the window to resize. On iOS, you're kinda constrained to the size of the device screen.)

iOS. But my root view is not UIViewController.view. I load it from xib(not storyboard) and add it as a subview of another view. Why should it be contrained to the size of the device screen?

> Why should it be contrained to the size of the device screen?


iOS uses one window, where macOS typically uses multiples.


Is your UIVC parent or child? How many views in your hierarchy?

I tried creating a view XIB, put a few things in it, added constraints between the contents, added constraints from the contents to the root view of the XIB, and I don't have any errors.


What specifically do the messages say is missing? What does IB add if you use the "Add Missing Constraints" function?

I suppose your subviews have explicit size constraints? Try putting 2 UILabels vertically and letting their intrinsic sizes determined the root view's size. Or just try my sample project.