Search code examples
swiftxcodeinterface-builderprogrammatically-created

Programmatically made view with rest of project in main.storyboard


I have a quick question for you guys that I havent found a definitive answer to. I have a app made with every viewcontroller designed in the main.storyboard. Recently I had to change out my table view viewcontroller for receiving data with collectionView in order to implement some more features.

But I have made this view programmatically. And I have made it exactly how I want it.. When I was done I wasnt sure if I could even use it with my main.storyboard made project. Atleast no similar question I have found has given me the exact answer to that.

So I figured I should ask you guys if thats possible and if it is.. if its a complicated process. This is my bachelor's thesis work so I am working against the clock.

If anyone knows, and maybe even have some tips on how I do this, I'd greatly appreciate it!


Solution

  • If your viewController conforms correctly to all the necessary methods; you should be able to create a viewController in your storyboard; hook it up the way you would any other uiObject; and then set the custom class in the attributes inspector to the class of your ViewController.

    If the view and not a viewController; you do a similar thing, drag the conforming type to your storyboard and subclass.

    If you'd like to see your view render on your storyboard; have the object declare @IBDesignable before the class declaration.

    @IBDesignable
    class myView: UIView {}