LoginSignup
4
4

More than 5 years have passed since last update.

Auto Layout で Scroll View のスクロール方向を制限して、内容を中央揃えにする

Last updated at Posted at 2016-02-02

概要

  • Scroll View のスクロール方向を制限します
  • Scroll View の中で要素を中央揃えにします

Apple のドキュメントの一部を目的に合わせて要約したものになっています。

イメージ

Content View の制約
スクリーンショット 2016-02-02 16.15.17.png

Scroll View のスクロール方向を制限する方法

縦横共通

  1. Scroll View の中に View を追加します (Content View と名前をつけておきます)
  2. Content View に以下の制約を追加します
  • Trailing Space to: Superview
  • Leading Space to: Superview
  • Bottom Space to: Superview
  • Top Space to: Superview

縦方向にだけスクロールさせる

Content View に Equal Width to: Superview の制約を追加します

横方向にだけスクロールさせる

Content View に Equal Height to: Superview の制約を追加します

Scroll View の中で要素を中央揃えにする

  1. 前述した縦方向にだけスクロールさせる制約を追加します
  2. Scroll View 内に表示したいすべての要素を Content View の中に追加します
  3. それぞれに Align Center X to: Superview の制約を追加します

ここで、1 の制約を追加しなかった場合、Scroll View の内容のサイズが決まらないので、中央揃えにすることができません。

4
4
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
4
4