Forked from bwhiteley/gist:049e4bede49e71a6d2e2
Last active
October 11, 2016 09:55
-
-
Save IamAlchemist/3dc917766e7ec6a708962e75ec7e5c26 to your computer and use it in GitHub Desktop.
Initialize Swift subclass of UIView, designed in .xib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 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) | |
guard let content = contentView else { return } | |
content.frame = self.bounds | |
content.autoresizingMask = [.FlexibleHeight, .FlexibleWidth] | |
self.addSubview(content) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment