Created
May 26, 2016 14:49
-
-
Save richy486/eb7b4f80f307f74cb752d28572658f45 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
// | |
// NibLoader.swift | |
// | |
// Created by Richard Adem on 5/26/16. | |
// Copyright © 2016 Richard Adem. All rights reserved. | |
// | |
// Modified from | |
// https://github.com/karthikprabhuA/CustomXIBSwift | |
// | |
import UIKit | |
protocol NibLoader {} | |
extension NibLoader where Self : UIView { | |
// Call in init methods | |
func addViewFromNib(withName nibName: String, bundle : NSBundle? = nil) { | |
let bundle = (bundle != nil) ? bundle : NSBundle(forClass: self.dynamicType) | |
let nib = UINib(nibName: nibName, bundle: bundle) | |
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView | |
view.frame = bounds | |
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] | |
self.addSubview(view); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment