Skip to content

Instantly share code, notes, and snippets.

@yabenatti
Created November 10, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yabenatti/c44760b06227310b70af63dd3adc366e to your computer and use it in GitHub Desktop.
Save yabenatti/c44760b06227310b70af63dd3adc366e to your computer and use it in GitHub Desktop.
CustomView
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