Code: Custom UIView from xib

If you are building a complex view, you can break it down in parts to make more readable the code and split the functionality on different UIView classes. Then you can instantiate your subviews from your main UIViewController.

CustomView.xib

Create your xib file with you own design and don’t forget set up as “CustomView” in the identity inspector.

customView

CustomView.h

 

CustomView.m

In your view controller:

That’s it, an easy way to load and manage custom views.

4 Comments
  • BK
    June 24, 2014

    I found this to be the easiest and cleanest solution for loading a custom uiview from a xib. Thanks!

  • Gaurav Singla
    September 14, 2014

    Superb Example David !!
    You saved my lot of time, Thanks !!!

  • Edwin
    November 18, 2014

    Hi, can you explain a little bit the configureWithDelegate function. Thank you.

  • Felix Wong
    November 2, 2015

    Thank you. Now is 2015 and I need to maintain some bunch of very old codes written by someone else and this is what I need!

Write a Comment

Your email address will not be published. Required fields are marked *


eight + 6 =

Submitting this form, you agree with our Legal Notice and our Cookie Policy.