Simple UIView load from nib

xib-3210Loading a view from a xib requires you to instantiate a UINib object, providing a Nib name and bundle. On that UINib object you use the instantiate method, providing an owner and options. The general pattern is that the name of the Nib is the same as the name of the class, and the bundle used is the main bundle. I like to simplify this pattern to use a method called loadFromNib that has an optional parameter called name where you can provide the exact name of the nib to load the view from. If the name parameter is not provided, the name of the nib is assumed to be the same as the class name. Since that is usually the case, you don’t have to provide a name parameter, just use e.g. let myView: MyView = loadFromNib().

To check out a sample project visit my GitHub repo: https://github.com/lukagabric/LoadFromNib

If you liked this blog post I’d appreciate if you followed me on Twitter

Related Post

Remember to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someone

Leave a Reply

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