4

I can change the class of the view in an UIViewController using the Storyboard like so: enter image description here

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Vladislav
  • 1,392
  • 1
  • 12
  • 21

1 Answers1

9

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: ...)
}
Tomas Jablonskis
  • 4,246
  • 4
  • 22
  • 40
Paulw11
  • 108,386
  • 14
  • 159
  • 186