I have a custom subclass of UIButton
in a framework, MyUI.framework
. In my app's storyboard I have a UIButton
with the MyUIButton
subclass set in the properties inspector.
This subclass is also an IBDesignable
, when the view designable updates, I can see the image.
When I run my application however, I get a crash. The bundle can be loaded but the resource is not there. Nor is the assets library when I do some URL-for-resource-ing calls on the bundle.
Here is my UIButton
subclass:
@IBDesignable
public class MyButton: UIButton
{
// MARK: - Setup
public override init(frame: CGRect)
{
super.init(frame: frame)
setup()
}
public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
setup()
}
public override func prepareForInterfaceBuilder()
{
super.prepareForInterfaceBuilder()
setup()
}
}
fileprivate extension MyButton
{
fileprivate func setup()
{
let bundle = Bundle(for: MyButton.self)
let normalImage = UIImage(named: "My Button", in: bundle, compatibleWith: nil)!
setImage(normalImage, for: .normal)
}
}