I have designed UIView as XIB with class. Can I use this xib, as existed example for other UIViews? So, I want create this UIView once and after use it in different parts of application.
Yes you can.
Once you've created the XIB, create a UIView class, assign that class to the XIB's file owner. Create an IBOutlet of the whole XIB container view attach it to the UIView class, call it something like containerView
On your XIB's custom class add the following:
override init(frame: CGRect) {
super.init(frame: frame)
customInit()
}
func customInit() {
Bundle.main.loadNibNamed("YourNIBName", owner: self, options: nil)
addSubview(containerView)
containerView.autoresizingMask = [.flexibleHeigh, .flexibleWidth]
}
On any of your ViewControllers now :
let view = CustomNib(frame: CGRect(x: 0, y:0, width: 150, height: 150)
self.view.addSubview(view)
You can also create this via the storyboard simply assign the custom xib class to any UIView.
Here is a great resource that can also help: Swift 3 — Creating a custom view from a xib