Created
July 6, 2020 21:30
-
-
Save BrunoScheltzke/9f3274c1d8e02b3e7e40948ea25c99c2 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
// | |
// NibLoadableView.swift | |
// BenditasMaes | |
// | |
// Created by Bruno Scheltzke on 10/06/20. | |
// Copyright © 2020 App5m. All rights reserved. | |
// | |
import UIKit | |
@IBDesignable | |
class NibLoadingView: UIView, ReusableView { | |
@IBOutlet weak var view: UIView! | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
nibSetup() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
nibSetup() | |
} | |
private func nibSetup() { | |
backgroundColor = .clear | |
view = loadViewFromNib() | |
view.frame = bounds | |
view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
view.translatesAutoresizingMaskIntoConstraints = true | |
addSubview(view) | |
} | |
private func loadViewFromNib() -> UIView { | |
return Self.nib.instantiate(withOwner: nil, options: nil).first as? UIView ?? UIView() | |
} | |
} | |
protocol ReusableView: class { | |
static var reuseIdentifier: String {get} | |
} | |
extension ReusableView { | |
static var reuseIdentifier: String { | |
return String(describing: self) | |
} | |
static var nib: UINib { | |
return UINib(nibName: self.reuseIdentifier, bundle: Bundle.main) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment