xcodeswiftinterface-builderibinspectable

Custom UIView with @IBInspectable func or Selector


I'm working with Swift and learning about @IBInspectable. I would like to know if it's possible create a custom view that allow other views and viewControllers to set a inner button action, as a ViewController links an IBAction directly to a button that it has.

I can create a @IBInspectable in my custom view with Selector type, but it's not visible to other classes in Interface Builder.

@IBInspectable private var touchUpInside =
NSSelectorFromString("didClickButton") {
   didSet {
        button.addTarget(self, action: "touchUpInside", forControlEvents: UIControlEvents.TouchUpInside)
   }
}

But not visible

enter image description here

Thanks!


Solution

  • The only types that are IBInspectable are: booleans, strings, numbers (primitives and types), CGPoint, CGSize, CGRect, UIColor, NSRange, and UIImage.

    NSSelector isn't a valid type.

    Even if it was it wouldn't show up in the outlets inspector but the attributes inspector. You posted a screen shot of the outlets inspector.