How to load an image in prepareForInterfaceBuilder with a IBDesignable UIImageView

后端 未结 7 2230
迷失自我
迷失自我 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:25

    For Swift 2 and Xcode 7, the interface has been changed. Should use

    let bundle = NSBundle(forClass: self.dynamicType)
    let image = UIImage(named: "imageName", inBundle: bundle, compatibleWithTraitCollection: self.traitCollection)
    let imageView = UIImageView(image: image)
    

    I use it in my project, it works fine for both IB and device.

    0 讨论(0)
提交回复
热议问题