Skip to content

Instantly share code, notes, and snippets.

@wanbok
Created November 19, 2015 05:53
Show Gist options
  • Save wanbok/18410c96c82ceb85fa6b to your computer and use it in GitHub Desktop.
Save wanbok/18410c96c82ceb85fa6b to your computer and use it in GitHub Desktop.
XIB UIView template with Autolayout
//
// XIBTemplateView.swift
// JanuaryEffect
//
// Created by Wanbok on 2015. 11. 18..
// Copyright © 2015년 JanuaryEffect. All rights reserved.
//
import UIKit
class XIBTemplateView: UIView {
// MARK: Initializer
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
setup()
}
init() {
setup()
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
func setup() {
let view = NSBundle.mainBundle().loadNibNamed(classNameAsString, owner: self, options: nil)[0] as! UIView
self.addSubview(view)
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["view": view]))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["view": view]))
self.backgroundColor = UIColor.clearColor()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment