Skip to content

Instantly share code, notes, and snippets.

@juliengdt
Forked from bwhiteley/gist:049e4bede49e71a6d2e2
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliengdt/e1c143a7e6652458bb0b to your computer and use it in GitHub Desktop.
Save juliengdt/e1c143a7e6652458bb0b to your computer and use it in GitHub Desktop.
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
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("CustomView", owner: self, options: nil)
contentView.frame = self.bounds
contentView.autoresizingMask = .FlexibleHeight | .FlexibleWidth
self.addSubview(contentView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment