Created
May 23, 2018 14:00
-
-
Save superhard/48895dbd873f4c4b2cbcb001e89e2133 to your computer and use it in GitHub Desktop.
Swift view custom initializer
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 characters
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