Last active
          March 12, 2019 04:13 
        
      - 
      
- 
        Save Shinolr/e7d35518ddfe40d4999943523e2ffa57 to your computer and use it in GitHub Desktop. 
Revisions
- 
        Shinolr revised this gist Mar 12, 2019 . No changes.There are no files selected for viewing
- 
        Shinolr created this gist Mar 12, 2019 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class SameNameWithXibFile: UIView, XibReusable { var contentView: UIView! required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) xibSetup() } override init(frame: CGRect) { super.init(frame: frame) xibSetup() } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ protocol XibReusable: AnyObject { var contentView: UIView! { get set } func xibSetup() } extension XibReusable where Self: UIView { func xibSetup() { contentView = loadViewFromNib() contentView.frame = bounds contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] addSubview(contentView) } func loadViewFromNib() -> UIView { let bundle = Bundle(for: type(of: self)) let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle) let view = nib.instantiate(withOwner: self, options: nil).first as? UIView return view! } }