Infamous911
Infamous911

Reputation: 1531

Xcode 6.3.2 - iOS - Ambiguous UIImageView

I want a UIImageView to expand based on the actual image's height and width. Specifically, I take the image's height and width, and then divide both by ([larger value] / 300) so that the aspect ratio is maintained and the image is optimized to fit in the space I have designed for it (a width that is never smaller than 320 and a height that is always exactly 320). In the code I give the UIImageView the new height and width that I acquired from this procedure. All of this works exactly as I intend it to when viewed in the iPhone Simulator. However, Xcode is giving me warnings about my constraints for the UIImageView, saying that the "position and size" are ambiguous. What is the correct way to make these warnings go away?

Here is the ViewController:

https://i.sstatic.net/cfTcx.png

And here are the constraints I have for the UIImageView in the middle:

https://i.sstatic.net/aMLPB.png

Upvotes: 1

Views: 346

Answers (2)

Saheb Roy
Saheb Roy

Reputation: 5957

If you are intending your imageview to expand, then you got to give a bigger values to the Imageview's Content Hugging property, By Default its 250, give its horizontal and vertical value as 751 as 750 is the default value for Content Compression, so u have to give it a bigger value than that. Tell me if this works.

Upvotes: 0

Malik Boy
Malik Boy

Reputation: 132

For maintaining aspect ratio and showing image, you don't have to do manual calculations. Just set the following property of UIImageView and assign the image to it

yourimageView.contentMode = UIViewContentModeScaleAspectFit; 

For keeping UIImageView in the center of screen, use following autolayout constraints

  • Constant Height
  • Constant Width
  • Horizontal Center in Container
  • Vertical Center in Container

Upvotes: 1

Related Questions