I can change the class of the view in an UIViewController using the Storyboard like so:
How can I achieve the same effect programmatically? I've tried this:
convenience init() {
print("convenience init")
self.init(nibName: nil, bundle: nil)
self.view = MTKView()
}
But it doesn't work. Seems to change the view for the MTKView, but the frame doesn't resize like it does when doing this by the Storyboard.
You should implement the loadView
function in your view controller and assign an instance of your custom view to the view controller's view
property:
override func loadView() {
self.view = MyCustomView(frame: ...)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With