- After creating CustomView.Swift & CustomView.xib in CustomView.xib as Class in File's Owner position set CustomView
- Then add func
commonInit
toinit(frame:)
andinit(aCoder:)
and you're ready to go.
CustomView.Swift
class CustomView : UIView {
@IBOutlet weak private var contentView:UIView!
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
}
required init?(coder aDecoder: NSCoder) { // for using CustomView in IB
super.init(coder: aDecoder)
self.commonInit()
}
private func commonInit() {
NSBundle.mainBundle().loadNibNamed(String(self.dynamicType).componentsSeparatedByString("__").last!, owner: self, options: nil)
contentView.frame = self.bounds
contentView.autoresizingMask = [FlexibleHeight, .FlexibleWidth]
self.addSubview(contentView)
}
}