Skip to content

Instantly share code, notes, and snippets.

@vmaraccini
Last active January 5, 2019 10:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmaraccini/ed177f2fb490d3754a7430191c91827a to your computer and use it in GitHub Desktop.
Save vmaraccini/ed177f2fb490d3754a7430191c91827a to your computer and use it in GitHub Desktop.
import UIKit
/**
**Contains the inteface elements of a screen or screen fragment**
Contains labels, buttons, etc and is responsible for the layout.
**Lifecycle:**
1. `init()`
2. `initialize()` *Add subviews*
3. `installConstraints()` *Layout*
- The methods themselves do nothing, it's up to the custom implementation
*/
open class BaseView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
required public init() {
super.init(frame: CGRect.zero)
self.setup()
}
/// Default implementation does nothing
open func initialize() {}
/// Default implementation does nothing
open func installConstraints() {}
// MARK: Private
fileprivate func setup() {
self.initialize()
self.installConstraints()
}
}
@edulpn
Copy link

edulpn commented Nov 23, 2018

🏅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment