For Swift 4.2
Let's assume you have a class named NibView and associated nib file is NibView.xib
class NibView: UIView {
class func getScreen() -> NibView {
let xib = Bundle.main.loadNibNamed(String(describing :self), owner: self, options: nil)
let me = xib![0] as! NibView
return me
}
}
create an instance of the class and add in your view with your specific layout whatever you want
let myView = NibView.getScreen()
self.yourView.addSubview(myView)