0
votes

I want to center an UIView containing a UIImageView in an other UIView both horizontally and vertically.

So i placed all Items in Interface Builder and set Constraints for center vertically and horizontally. Then i added max height and width to avoid the inner UIView excessing the outer UIView. But still Interface Builder tells me I need to specify X and Y Constraint for the inner UIView.

What did i do wrong?

Reason i'm needing this is, i need a UIImage which can be landscape or portrait format displayed centered in the UIView. Also there should be an Icon overlaying the UIImage in the lower right corner. So i thought best solution would be to make a UIView containing both images and place it centered in the main uiview. But it seems autolayout won't let me do this.

Can somebody hint me in the right direction please?

EDIT

For more Clarification on what i want.

I need a UIView having its Center Point fixed at exaclty one point in its superview. How can i do this with maintaining flexible height and width and using autolayout?

1
did you set autolayout for both imageview & inner uiviewGagan_iOS
I set autolayout constraints for all uiimageviews and uiviews. they are all correct and accepted by interfacebuilder. Only thing it complains about is not having a X and Y constraint for the uiview with the flexible height and width.Maverick1st
What is going on is , You have Constraints for center vertically and horizontally. But it is not satisfying height . & Width Constraints ,means your view knows from where it should be centre but it has no fixed height and width to satisfy autolayout enginePrashant Tukadiya
i need a UIImage which can be landscape or portrait format displayed it is not been possible to set Uiview as per image content mode (i.e if image is aspect fit ) in case of image your image has some space from left and right part and same with portraitPrashant Tukadiya
flexible height and width of what ?, subview should resize ? , yes then according to what ?Prashant Tukadiya

1 Answers

-4
votes

Use horizontal,vertical and Leading enter image description here