"Content View" in a custom UIView, as in Cells

I want to achieve a similar behaviour as exists for Table/CollectionViewCells, where when editing a Storyboard/XIB, Xcode adds views into a "Content View" subview instead of a view itself.

Is there any markup or protocol, that instructs Xcode to add views to view's "contentView" as it does for cells?

May be I miss your point. Could you explain why you want to do it ?

What about creating such a contentView in IB, with its IBOutlet and position all subviews inside this contentView ?

Or you can create a contentView in code and ad this as a subview of the view.

Is there any markup or protocol, that instructs Xcode to add views to view's "contentView" as it does for cells?

Plain old views don’t have a concept of a content view. If you want to achieve a design similar to table cells or collection view cells, then you need to implement it all yourself.

Is the goal to make your custom cell type (packaged in a library) acquire custom design-time behaviors like UIKit cell types when placed in a storyboard? That is, there would be a content view already present inside your main cell view in the storyboard? Unfortunately this sort of customization isn’t supported. The user can put your cell type into a storyboard (by dragging in a regular UIView and then changing the class name) but it will always just be a plain UIView as far as Xcode is concerned.

You can let the user customize your cell in certain well-known ways of course, such as by IBOutlet (maybe require the user to install their own content view and hook it up to an outlet named contentView), and you can expose extra properties via IBInspectable or IBDesignable.

By “implement it all yourself” I meant that at run time you could add behavior such as re-parenting all the user’s direct subviews into a custom content view that you create, setting up constraints to achieve a desired layout style, etc.

"Content View" in a custom UIView, as in Cells
 
 
Q