Search code examples
iosswiftuiviewautolayoutstoryboard

Swift Align Leading Edge with Trailing Edge


I have a label that I want as the x axis label on my graph, and I want to align the trailing edge of the label to the graph view, and also the top edge to the bottom edge of the graph view, how can I do this? I am building it via storyboard

storyboard screenshot with constraints enter image description here


Solution

  • I record my screen to get what you want :

    https://giphy.com/gifs/JbnR5F1ZFogb7gSojT/fullscreen (Sorry for the gif-quality)

    Just keep pressing control and drag your mouse from the UILabel to the graph view to do the same thing.

    1. Add horizontal spacing
    2. Add bottom constraint
    3. Select the bottom constraint by clicking the blue line that represents it
    4. Change relation to first item (your label) from Bottom to Top value

    If I misunderstood what you want and you wanted the following:

    enter image description here

    Just select the horizontal spacing constraint by selecting the blue line that represents it, and adjust the constraint's settings with the following :

    enter image description here