UIImageView Scaling

Rick Aurbach

I have a UIImageView, which I load with the following function:

func loadData() {

guard let recipe = recipe,

let fileN = recipe.photo,

!fileN.isEmpty else {

imageView.image = nil




let filePath = ImageUtils.fileURL(fileName: fileN, directory: .applicationSupportDirectory)!.path

imageView.image = UIImage(contentsOfFile: filePath)

imageView.contentMode = .scaleAspectFit




I create a new image using a standard UIImagePickerController. In its imagePickerController(_ picker:didFinishPickingMediaWithInfo info:) delegate method, I save the image to a file (in the .applicationSupportDirectory) and save the image name in my database. Then I dismiss the pickerController, and call the above loadData() method in it's completion handler.

I observe two cases. In all cases except the above "exit from picker" case, the image is shown scaled to fit in the UIImageView. But in the case of "exit from picker", the upper left corner of the image is shown in the UIImageView at its full size.

Does anyone have any idea what might be happening here? And what I can do to get the (desired) effect of displaying the image scaled to its imageView in all cases?


Rick Aurbach

Join cocoa@apple-dev.groups.io to automatically receive all group messages.