iosswiftinterface-builderiboutletuicontrol

How to show subclass of UIControl in View Controller


I would like to be able to interact with the UIControl I have made, and therefore want it in my ViewController.

What I tried

But in Interface Builder I am not able to set my outlets to the buttons contained in the new class (1)?!

1: 1



2: 2



UIControl's documentation confirms that it is a subclass of UIView, and I should therefore be able to connect the outlets, right?

What am I missing here? :/


Solution

  • Of course, you can't add an @IBOutlet because the buttons that you've added to WeekdayControl are in UIViewController.

    You can't add an @Outlet to WeekdayControl buttons are only subviews of WeekdayControl.

    UIViewController is the boss here, and you can only add an @outlet to UIViewController.

    Better create your buttons programmatically in WeekdayControl.