4

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!

Viton
  • 67
  • 5
  • Same as [IBDesignable… adding custom actions?](http://stackoverflow.com/questions/35799945/ibdesignable-adding-custom-actions) – mfazekas Jul 29 '16 at 17:30

1 Answers1

1

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.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
  • Thanks Sean. What I really wanted is to link an Action via @IBAction like UIButton does, but tried a lot and couldn't get it. DO you know if it's possible from a custom view? – Viton Jul 21 '15 at 19:44