Search code examples
autolayoutnslayoutconstraint

how to adjust space between buttons equally using AutoLayout


I have a main screen with three button vertically aligned. I want adopt my app for 4" screen. so I want to adjust space between buttons equally to fill the screen. see the below images: how can I accomplish that using AutoLayout?

the green area keeps its size.

enter image description here enter image description here


Solution

  • Edit: Apple now favors the use of stack views for this purpose. See this WWDC 2013 video for OS X and this iOS one from WWDC 2015

    The Apple approved way of doing this (look for section titled "Creating Equal Spacing Between Views") is to insert hidden views between each of your buttons and set those views' heights to be equal.

    See my answer over here for some discussion on why this approach makes sense.