Search code examples
iosswiftconstraintssnapkit

Find the lowest positioned element


I'm trying to make constraints via Snapkit in a table view cell but my problem is I need to find out which element has max y position (The lowest one).

I have an UIImageView and next to image view UILabel elements. The label text is dynamic and could be very long or very short. Below these 2 elements, I have another one that should be aligned based on the label height, either taking image view or label.

My question is how to find which element (UIIMageView, UILabel) has a bigger Y position.

To be more clear I attached a draw with simple two cases.enter image description here


Solution

  • Set a greaterThanOrEqualTo constraint on both elements.

    In "plain language":

    • AnotherElement.top >= ImageView.Bottom (with constant of 12, or however much space you want)
    • AnotherElement.top >= Label.Bottom (with constant of 12, or however much space you want)