Search code examples
iosuitableviewxcode9

Place label on top of each other next to an image


I'm trying to place a label on top of label next to my image.

enter image description here

I have tried

enter image description here

I had

enter image description here

I want these number to display here

enter image description here

Should I look into a stack or some short?


Solution

  • In this case, I might be tempted to just use a UIStackView - it might be a little overkill, but one of the benefits is if you hide one of the labels (because it's text is nil) it will reduce the size of the StackView, which, personally, makes the layout look nicer, but that's me

    General layout...

    General layout

    UIImageView constraints

    UIImageView constraints

    UIStackView constraints

    StackView constraints

    UIStackView properties

    UIStackView properties

    *nb: This still assumes that the overall height of the text won't exceed the height of the UIImageView