Is it possible to create an @IBOutlet in a custom view?

No XIB is needed

  1. Manually write the IBOutlet in your custom UIView class, for example: @IBOutlet weak var container: UIView!

  2. Open the storyboard and select the custom view in the Document Outline panel on the left.

  3. Open the Connections Inspector on the right. Drag from the Outlet to the custom view in the Document Outline panel to connect them.

Connect custom view's IBOutlet to view in Interface Builder


If you want to reuse a UIView then best to create an xib of the view and a custom class of the UIView. Then change the file owner in xib class to your custom class. Then you can drag and drop IBOutlets of the components inside the view to custom class. In the storyboard you can use the custom view and change the name of the class of view to custom view. Now drag and drop the IBOutlets from the story board to UIView. You can see the tutorial video on how to do , I have made for you. https://youtu.be/IrgH522lbfA