When I write my own UIButton-extended class and make it @IBDesignable, I receive two errors in Interface Builder, namely:
I found something really important when using an UIImage in any class marked @IBDesignable. The classic UIImage init would crash the agent:
let myImage = UIImage(named: String) // crash the agent
The solution is to use this init method of UIImage:
let myImage = UIImage(named: String, in: Bundle, compatibleWith: UITraitCollection)
Working code example:
let appBundle = Bundle(for: type(of: self))
let myImage = UIImage(named: "myImage", in: bundle, compatibleWith: self.traitCollection))
Where self is your class with the @IBDesignable keyword. Xcode 9.4, Swift 4.1