Roman M.
Roman M.

Reputation: 101

UIImage works on simulator but crashes on device swift

I have checked UIImage works on the simulator but not working on the device. Here's the code:

imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
let image = UIImage(named: "sample.png")
imageView.image = image
view.addsubview(imageView)

How can I solve this problem?

Upvotes: 0

Views: 261

Answers (2)

My Favorite Bear
My Favorite Bear

Reputation: 114

Extremely larger images bigger than UIImageView size causes the crash. UIImageView size is 50 x 50, but the image size is 900 x 900. This works on simulator but doesn't work on iOS device.

Upvotes: 3

Basheer
Basheer

Reputation: 1207

You need to add your image to 'Copy Bundle Resources'.

Select Target -> Build Phases -> Copy Bundle Resources and add your image to the list.

enter image description here

Upvotes: 0

Related Questions