Last active
March 23, 2018 23:00
-
-
Save NikKovIos/69d8a1d81ac6897ff1d3bdd878ded51a to your computer and use it in GitHub Desktop.
Swift class to initialize UIView from xib
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
// | |
// NibInitializableView.swift | |
// nik-kov.com | |
// | |
// Created by Nik Kov on 16.11.17. | |
// Copyright © 2017 Nik Kov. All rights reserved. | |
// | |
/// Just subclass it | |
@IBDesignable | |
class NibInitializableView: UIView { | |
weak var view: UIView! | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
nibSetup() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
nibSetup() | |
} | |
func nibSetup() { | |
backgroundColor = .clear | |
view = loadViewFromNib() | |
view.frame = bounds | |
view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
view.translatesAutoresizingMaskIntoConstraints = true | |
addSubview(view) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment