0

I have an UIImageView in my VC. I wanted to put an image into it. The imageView has 4 constraints: 8 of distance to all directions. When I load the screen it automatically makes a big white space and I don't know why.

The problem is that I am not sure if its really the UIImageView producing the white space. If I set the content mode to scale to fit there is still an white space. But if I am looking in debugging mode where the space comes from it says from the UIImageView. Here a picture of my debugging so that you hopefully know what I am mean:

White Space Image

EDIT: I tried to print out the imageView.frame.height it passes back 0. Can this be? In my debugger the imageView.height = 400 Why I can't print out imageView.height? I get an error with "imageView has no member height"

EDIT2: I tried it now with some different sized pictures ... every time I have a height of 400 in the end

Alladinian
  • 34,483
  • 6
  • 89
  • 91
tommitomtom
  • 115
  • 1
  • 11

1 Answers1

0

If you want to centre the image set Centre X and Centre Y constraints along with height and width. Also try adding this code :

imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
CST
  • 313
  • 2
  • 10
  • my content mode is normally scale AspectFit ... I just changed it to scale to fit to show you that the white spaces are not really the image but the white spaces got created by the UIImageView – tommitomtom Jan 25 '17 at 10:20
  • can you post the constraints that you are setting? – CST Jan 25 '17 at 10:22