Created
June 8, 2018 02:44
-
-
Save isaac-weisberg/1cb1ce67c73604c592039988a64254dd to your computer and use it in GitHub Desktop.
Xib Modular View. Extend this class to load contents of your custom views from .nibs.
This file contains 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
// | |
// XibModularView.swift | |
// Pobjects | |
// | |
// Created by Isaac Weisberg on 4/5/18. | |
// Copyright © 2018 Isaac Weisberg. All rights reserved. | |
// | |
import UIKit | |
class XibModularView: UIView { | |
var xibContentView: UIView! | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
xib() | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
xib() | |
} | |
private func xib() { | |
xibContentView = UINib(nibName: "\(self.classForCoder)", bundle: .main).instantiate(withOwner: self, options: nil).first as? UIView | |
guard xibContentView != nil else { | |
return | |
} | |
xibContentView.frame = self.bounds | |
addSubview(xibContentView) | |
} | |
} | |
class XibModularTableViewCell: UITableViewCell { | |
var xibContentView: UIView! | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
xib() | |
} | |
private func xib() { | |
xibContentView = UINib(nibName: "\(self.classForCoder)", bundle: .main).instantiate(withOwner: self, options: nil).first as? UIView | |
guard xibContentView != nil else { | |
return | |
} | |
xibContentView.frame = self.bounds | |
contentView.addSubview(xibContentView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment