Does it have to be programmatically? You could add constraint between the two in the interface builder and achieve the same. To do this,
- control drag from the smaller to the larger and select aspect ratio,
- then select one of the views and go to the size inspector on the
right bar
- under Constraints, select the constraint that was just added, double
click it
- under First Item select shorterView.Height
- under Relation select Less Than or Equal
- under Second Item select tallerView.Height
- make sure Constant is 0 and Priority is 1000
- set the Multiplier to 1:4 (I believe this is the correct ratio, but I always just mess around with these numbers until I'm satisfied with the views)
I'm currently using this in one of my projects, and it's working really well, so hopefully it will work for you, too!
(The top answer here might also help :] )