Skip to content

Instantly share code, notes, and snippets.

@tanner0101
Last active August 29, 2015 14:27
Show Gist options
  • Save tanner0101/4e8e8a31553e46de81fe to your computer and use it in GitHub Desktop.
Save tanner0101/4e8e8a31553e46de81fe to your computer and use it in GitHub Desktop.
Instantiate a UIView object from a nib in the NSBundle.
/**
UIViewExtensions.swift
Instantiate a UIView object from a nib in the NSBundle.
<https://gist.github.com/tannernelson/4e8e8a31553e46de81fe>
*/
import UIKit
extension UIView {
class func instantiateFromNib(nibName: String) -> UIView {
var view = UIView()
var elements = NSBundle.mainBundle().loadNibNamed(nibName, owner: nil, options: nil)
for element in elements {
if let element = element as? UIView {
return element
}
}
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment