How to load an image in prepareForInterfaceBuilder with a IBDesignable UIImageView

后端 未结 7 2234
迷失自我
迷失自我 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条回答
  •  萌比男神i
    2020-12-23 15:13

    Lets pop in the swift 3 answer

    let bundle = Bundle(for: self.classForCoder)
    ... UIImage(named: "AnImageInYourAssetsFolderPerhaps", in: bundle, compatibleWith: self.traitCollection)!
    

提交回复
热议问题