Last active
August 29, 2015 14:27
-
-
Save tanner0101/4e8e8a31553e46de81fe to your computer and use it in GitHub Desktop.
Instantiate a UIView object from a nib in the NSBundle.
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
/** | |
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