Created
July 10, 2019 14:05
-
-
Save Hexfire/2cdda7e3e3a0be08be6da046757a38ee to your computer and use it in GitHub Desktop.
UIView.loadFromXib()
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
import UIKit | |
extension UIView { | |
static func loadFromXib() -> UIView? { | |
let bundle = Bundle(for: self) | |
let nib = UINib(nibName: String(describing: self), bundle: bundle) | |
let view = nib.instantiate(withOwner: self, options: nil).first as? UIView | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment