LoginSignup
13
11

More than 5 years have passed since last update.

【Swift4】AutoLayoutのStackViewを使ってボタンを等間隔に並べる

Last updated at Posted at 2018-02-21

実行環境

【Xcode】Version 9.2
【Swift】Version 4.0.3

概要

storyboardStackViewを使って、ボタンなどのアイテムを均等に並べる方法。

方法

アイテムを適当に並べます。
a.png

並べたアイテムを全て選んで、AutoLayoutツールバーにあるStackViewを選択します。
b.png

StackViewを選択すると、こんな感じにくっつきますが気にしない。
c.png

その状態で、ユーティリティエリアにあるDistributionからFill Equelly を選びます。
d.png

あとはStackViewに対していい感じに制約をかけてあげれば完成!
(今回は上下左右中央と両端からの距離を0にしています)
e.png

完成形

f.png

13
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11