How to expose actions in custom control implementation?

We know that in order to expose a property in Interface Builder.

@IBInspectable var starCount: Int = 5


How to do a same for IBAction, we want to control drag the custom control to interface builder and user can implement their own action for the event like button touchUpInside?

Replies

I've never seen it was possible in IB.


To ilmplement the action, you can subclass the button and overload the func.

The custom control inherited from UIStackView, which hasn't any IBAction.

We can implement the IBAction inside the custom control, but how to change the behavior in the calling inteface (ie. in a view controller)?

for example,

RatingControl : UIStackView.

we drag a RatingControl into the view controller (here we didn't do a sub class, just do a class instance of RatingControl), want to customize the behavior of the touchUpInside action.

Should I inherit from UIControl instead of UIStackView?

Apples's documentation at https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementingACustomControl.html was missleading?

Yes, t think so.