How to load an image in prepareForInterfaceBuilder with a IBDesignable UIImageView

后端 未结 7 2231
迷失自我
迷失自我 2020-12-23 14:27

I would like to load a sample image in an IB designable UIImageView, to be shown in Interface Builder while editing the interface. The following code does not w

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 15:07

    For Swift 4 (and 3) use this:

    let image = UIImage(named: "foo", in: Bundle(for: type(of: self)), compatibleWith: traitCollection)
    

    This approach gets the bundle universally

提交回复
热议问题