You use UIView when you already have a view, and you don’t need to have a dedicated view controller to create and handle interactions within it.
On the UIView help page :
The UIView object claims to be the rectangular region of its spanning superview (its parent in the hierarchy of views) and is responsible for the entire drawing in this region ...
Simplified structure: YourViewController --- (is) ---> UIView
You use UIContainerView when you need to embed another view controller in the one you already have. The built-in view controller is responsible for returning the view for the area that the UIViewContainer occupies. Therefore, your UIContainerView knows which view controller to use to render the UIView inside the area in which it occupies.
On the UIContainerView help page :
A Container View defines an area within a subgraph of a view of a view controller, which may include a child view controller.
Simplified structure: YourViewController --- (is) ---> SubViewController --- (is) ---> UIView
This SubViewController returns a view and processes its events.
Keenle
source share