Created
November 19, 2015 05:53
-
-
Save wanbok/18410c96c82ceb85fa6b to your computer and use it in GitHub Desktop.
XIB UIView template with Autolayout
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
// | |
// 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