Created
November 10, 2017 16:17
-
-
Save yabenatti/c44760b06227310b70af63dd3adc366e to your computer and use it in GitHub Desktop.
CustomView
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
import UIKit | |
@IBDesignable | |
class CustomView: UIView { | |
// MARK: - IBOutlets | |
@IBOutlet weak var centerImageView: UIImageView! | |
// MARK: - Init Methods | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
self.commomSetup() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
self.commomSetup() | |
} | |
private func viewFromNibForClass() -> UIView { | |
let bundle = Bundle(for: type(of: self)) | |
let stringNib = String(describing: type(of: self)) | |
let nib = UINib(nibName: stringNib, bundle: bundle) | |
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView | |
return view | |
} | |
private func commomSetup() { | |
let view = self.viewFromNibForClass() | |
view.frame = self.bounds | |
addSubview(view) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment