StoryboardやXIB上で設定したかったのでライブラリにしました。
インストール
pod "VerticalAlignmentLabel"
StoryboardやXIBでUILabelを貼り付けたら、Class
とModule
を以下のように変更します。
次にAttribute Inspectorに移動し、Top
またはButtom
をOnにします。
(*両方OnだとBottom
になります。)
実行結果
コード上の指定だとこのようになります。
// var label: VerticalAlignmentLabel
label.verticalTextAlignment = .top
label.verticalTextAlignment = .center
label.verticalTextAlignment = .bottom