I am using code to create a view (with subviews) for UIViewController, here is how I do it:
and this is how I create my own view:
class MyView: UIView {
override init (frame : CGRect) {
super.init(frame : frame)
addSubviews()
setupLayout()
}
convenience init () {
self.init(frame:CGRect.zero)
}
required init(coder aDecoder: NSCoder) {
fatalError("This class does not support NSCoding")
}
func addSubviews(){
}
func setupLayout(){
}
}
I do this for all of my View controllers, and I'm looking for a more elegant way, because this process repeats, so is there any solution for creating such a general one, for example, creating a super-abstract class or creating an extension for UIViewController and UIView, protocols? I'm new to Swift, and I think Swift may have a more elegant solution with its modern templates.
source
share