Skip to content

Instantly share code, notes, and snippets.

@richy486
Created May 26, 2016 14:49
Show Gist options
  • Save richy486/eb7b4f80f307f74cb752d28572658f45 to your computer and use it in GitHub Desktop.
Save richy486/eb7b4f80f307f74cb752d28572658f45 to your computer and use it in GitHub Desktop.
//
// 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