Last active
April 6, 2016 01:54
-
-
Save hiragram/4a7d2e24272a1cde15160eed70588a4a to your computer and use it in GitHub Desktop.
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 Foundation | |
| protocol NibInstantiatable { | |
| static var nibName: String { get } | |
| static func instantiateFromNibWithOwner(ownerOrNil: AnyObject?, options: [NSObject: AnyObject]?) -> Self | |
| } | |
| extension NibInstantiatable where Self: UIView { | |
| static var nibName: String { | |
| get { | |
| return String(Self.self) | |
| } | |
| } | |
| static func instantiateFromNibWithOwner(ownerOrNil: AnyObject?, options: [NSObject: AnyObject]?) -> Self { | |
| return UINib(nibName: nibName, bundle: nil).instantiateWithOwner(ownerOrNil, options: options).first as! Self | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can instantiate any custom view like:
And you only have to modify your custom view like:
Bye-bye