0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Swift]UIに比率を指定する(Storyboard)

Posted at

概要

StoryboardでUIの幅や高さを比率で指定する手順です。

全体の手順は
①比率の元にしたいオブジェクトと同じ幅(高さ)にする
②どれくらいの比率にするかを指定する

本文

今回は画面全体に対する比率を指定したいのでSafe AreaとButtonを選択する(Commandボタンを押しながら選択)
スクリーンショット 2022-08-11 20.15.07.png
画面右下、Add New ConstraintsからEqual Widthsを選ぶとボタンの横幅が画面の横幅と同じになります。
スクリーンショット 2022-08-11 20.16.47.png
スクリーンショット 2022-08-11 20.15.37.png
比率を指定したいオブジェクト(今回はButton)だけを選んだ状態にしてスクショのように選択し、Multiplierに比率を入力します。
(初期値1は「100%=同じ」を意味します。今回は画面横幅の半分なので0.5を入力しました)
スクリーンショット 2022-08-11 20.17.43.png
スクリーンショット 2022-08-11 20.16.14.png

補足

この手順を応用すると、他のUIに対する比率を指定することもできます。
今回作ったボタンに対して半分の幅を黒色のボタンに指定してみました。
スクリーンショット 2022-08-11 20.23.41.png

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?