Created
March 30, 2020 14:41
-
-
Save alvaroroyo/0acc0d6f525f3662eacec47429614f0f to your computer and use it in GitHub Desktop.
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
class UIXibView: UIView { | |
public var nibName:String? { return String(describing: type(of: self)) } | |
public var contentView: UIView! | |
override public init(frame: CGRect) { | |
super.init(frame: frame) | |
awakeFromNib() | |
} | |
required public init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
override open func awakeFromNib() { | |
super.awakeFromNib() | |
guard let nibName = self.nibName, | |
let view = Bundle.main.loadNibNamed(nibName, owner: self, options: nil)?.first as? UIView | |
else { return } | |
self.layoutIfNeeded() | |
contentView = view | |
contentView.frame = self.bounds | |
contentView.autoresizingMask = [.flexibleHeight,.flexibleWidth] | |
self.addSubview(contentView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment