Created
May 31, 2018 15:10
-
-
Save migueltg/69fbf7c75399d2ca3eecd50b839251c5 to your computer and use it in GitHub Desktop.
Load view from nib in xcode for storyboard and code
This file contains 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
func loadViewFromNib(nibName: String? = "\(self)") { | |
guard let nibName = nibName else { return } | |
let bundle = Bundle(for: type(of: self)) | |
let nib = UINib(nibName: nibName, bundle: bundle) | |
guard let view = nib.instantiate(withOwner: self, options: nil).first as? UIView else { return } | |
view.frame = bounds | |
view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
addSubview(view) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment