Siddharthan Asokan
Siddharthan Asokan

Reputation: 4441

UIImageview Resizes on autolayout

I'm having a view controller interface as shown below: enter image description here

I'm using autolayout. There is no constraint set. When I run the app on an iPhone 5 the image covers up the entire view. I have set the content mode for the imageview to be aspect fit. The screen on loading the image from the avcapture session looks like the one below:

enter image description here

This is just the top image view. What constraints should I be adding on to the image view to achieve what it looks like on the interface builder?

Upvotes: 0

Views: 795

Answers (1)

Dhaivat Vyas
Dhaivat Vyas

Reputation: 2928

As per your question you need to add this constraints.

1) To First UIImageView :

-Top
-Bottom from Second Image
-Leading
-Tailing
-Height(If Required)
-Center Horizontally(If required)
-Width(If you want fixed width according to center.)

2) To Second UIImageView :

-Bottom to UIView
-align left from first image view(It will align left of both the image views)
-align right from first image view(It will align right of both the image views)
Note: As you have set the left and right align to both the image views your second image view will have similar width as first image view and it will also work as leading and tailing constraints. So no need to set leading and tailing constraints to second image view.
-Vertical spacing between first and second(It might not be necessary as you may have set bottom to first view)
-Height (If necessary)

You can visit below links it will be helpful in solving your problem of auto layout.

https://stackoverflow.com/a/26191428/4101371

In the above link answer i've added two links which will help you set auto layout constraints.

You can also visit this "Constraints for multiple controls:"

https://stackoverflow.com/a/27471120/4101371

Hope this might solve your problem.

Upvotes: 1

Related Questions