swiftxcodecustom-controlsiboutlet

Swift - Custom View with xib file, IBOutlet is nil


I have a custom button designed using xib file like this: enter image description here

and I connect it to my storyboard like this:

enter image description here

but when I run the app, I got runtime error complaining that IBOutlet ivRightIcon is nil

@IBInspectable var rightIcon: UIImage? = nil{
    didSet{
            ivRightIcon.image = rightIcon
        }
    }
}

My outlet is connected in xib file correctly I'm using Swift 3 and xCode 8.2.1 Please help!


Solution

  • I managed to solve this. I should set the View class as UIButton and File's Owner as my custom button class