0

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)
    }
}
Adam Carter
  • 4,741
  • 5
  • 42
  • 103
  • Update. PNGs are loading but PDFs are not. Submitted a bug to Apple – Adam Carter Mar 04 '17 at 23:39
  • Update. This seems like a simulator only issue as running on the device works as expected. Can anyone else verify this as a problem with `UIImage(named:in:compatibleWith:)` using PDF single scale image assets? – Adam Carter Mar 05 '17 at 09:57

0 Answers0