Skip to content

Instantly share code, notes, and snippets.

@Hexfire
Created July 10, 2019 14:05
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 Hexfire/2cdda7e3e3a0be08be6da046757a38ee to your computer and use it in GitHub Desktop.
Save Hexfire/2cdda7e3e3a0be08be6da046757a38ee to your computer and use it in GitHub Desktop.
UIView.loadFromXib()
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