UIKit Custom UIView with XIB: How to improve your productivity by 10 times with Custom Views

KD Knowledge Diet
2 min readMay 13, 2022

It is no exaggeration to say that the history of software development was written by reusability. Almost all development tasks end up being one. ‘Reusability’. So, today, I am going to introduce how to create a custom view using xib.

[1] Create Custom View with xib

Create View

[2] Create Cocoa Touch Class, UIView

Cocoa Touch Class

[3] Connect your xib file with cocoa touch class by specifying its name on the right panel.

Match your cocoatouch class with xib file
Match your cocoatouch class with xib file

Many other tutorials would tell you to set FileOwner. But no need for taht!

[4] Apply Freeform

Freeform

It’s not necessary. But assuming that you are create a view instead of the entire screen, choosing Freeform will be much more helpful.

[5] Design your component!

I added label both horizontally and vertically centered

[6] Load Nib

Load Nib

[7] Check!

It works!

Conclusion

  1. Create xib File
  2. Create CocoaTouch Class UIView
  3. Connect your xib File with CocoaTouch class through Custom Class
  4. Load Nib Programmatically

--

--

KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!