NSPratik
NSPratik

Reputation: 4858

Make super view's height flexible based on child view's aspect ratio

Attached image shows Whatever I want..

enter image description here

From image, you can see that B and C are subviews of A (Dark blue border indicated view A). B is having aspect ratio (B's height would be based on its width). C will have fixed height.

I want such a combination of constraints so that, height of A should be based their subview's calculation.

Upvotes: 0

Views: 413

Answers (3)

Bhadresh Mulsaniya
Bhadresh Mulsaniya

Reputation: 2640

Below are the constraints set for view hieararchy:

enter image description here

For View A :

enter image description here

For View B :

enter image description here

For View C:

enter image description here

Also you can set View B's constraint like this way if you don't want square always:

enter image description here

Upvotes: 2

Ketan Parmar
Ketan Parmar

Reputation: 27448

You constraints should be like,

View A,

leading, Trailing, Top

View B,

leading, trailing, top, bottom and aspect ratio

View C,

leading, trailing, bottom and fix height

Hope this will help :)

Upvotes: 1

Vladimir K
Vladimir K

Reputation: 1382

Here is what constraints you need:

For View A:

enter image description here

For View B:

enter image description here

For View C:

enter image description here

Upvotes: 2

Related Questions