Search code examples
iosimageswiftuiimageviewscale

Swift: Edit image taken from camera to fill a UIImageView


I have used a UIImageView that takes its image from the default camera app using UIPicker. But the image I am getting is too small to fit into the image view and if I use:

        imageView.contentMode = UIViewContentMode.ScaleToFill

While this indeed scales to fit the image view the picture looks like it has been mashed up and not particularly good. I was wondering if it was possible to scale the image up in such a way that the quality of the image does not get bad.


I am using Swift 1.2 and thanks for any help! :D


Solution

  • It will work with:

    myImageView.contentMode = .ScaleAspectFit
    

    Camera images are usually bigger than a UIImageView on a device. To shrink them quickly to a visible size, the best way is to set the .contentView property of UIImageView to .ScaleAspectFit.