Nicholas Muir Nicholas Muir - 1 year ago 156
Swift Question

Creating IBoutlet from UIView in custom UIView class swift

I have a UIView with a UIlabel and a UIImage inside it placed on my view controller.

I created a custom class for the UIView and tried to create an IBoutlet for the UIImage and UILabel in the custom class but i will not let me drop it.

I have already clicked on the UIView and set its class to the custom class, so I am not sure why it is not letting me create the outlet.

Below is a screenshot of the custom class, uiview (With image and label). You may have to click on it to see it.

enter image description here

Thanks for your help

Answer Source

In your situation, you should connect the outlets to a view controller instead of a view.

Instead of creating a UIView subclass, you should create a UIViewController subclass:

class FrontViewController: UIViewController {


Next, select your view controller in the storyboard. In the Identity Inspector (select the tab with an ID card on the panel on the left), type "FrontViewController" (the name of your class) into the "Class" field.

enter image description here

Now you should be able to drag outlets to the class!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download