LoginSignup
13
9

More than 5 years have passed since last update.

SwiftでUILabelの縦揃えをする

Last updated at Posted at 2016-12-11

StoryboardやXIB上で設定したかったのでライブラリにしました。

インストール

pod "VerticalAlignmentLabel"

StoryboardやXIBでUILabelを貼り付けたら、ClassModuleを以下のように変更します。

スクリーンショット 2017-09-04 0.11.13.png

次にAttribute Inspectorに移動し、TopまたはButtomをOnにします。
(*両方OnだとBottomになります。)

スクリーンショット 2017-09-04 0.14.55.png

実行結果

SS1.png

コード上の指定だとこのようになります。

// var label: VerticalAlignmentLabel

label.verticalTextAlignment = .top
label.verticalTextAlignment = .center
label.verticalTextAlignment = .bottom
13
9
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
9