Skip to content

Instantly share code, notes, and snippets.

@superhard
Created May 23, 2018 14:00
Show Gist options
  • Save superhard/48895dbd873f4c4b2cbcb001e89e2133 to your computer and use it in GitHub Desktop.
Save superhard/48895dbd873f4c4b2cbcb001e89e2133 to your computer and use it in GitHub Desktop.
Swift view custom initializer
class MyView: UIView {
convenience init(args: Whatever) {
self.init(frame: CGRect.zero)
//assign custom vars
}
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit() {
//custom initialization
}
override func updateConstraints() {
//set subview constraints here
super.updateConstraints()
}
override func layoutSubviews() {
super.layoutSubviews()
//manually set subview frames here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment