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 5 years have passed since last update.

iOS で 画像の横を画面ギリギリまで広げて、高さをアスペクト比で伸ばした画像にする方法

Posted at

やりたいこと

  • 端末毎に横サイズが異なるので、横幅を固定値で指定したくない
    • 左右マージン20pxとかにしたい
  • 高さはアスペクト比維持していい感じに伸びて欲しい
  • 画像のアスペクト比は崩さないで欲しい

結論

  • 左右に20pxのマージン制約つける
  • 画像にアスペクト比の制約をつけて、画像毎のアスペクト比を指定する
  • content mode は scale to fit にする

蛇足. 試したけどダメだったこと

左右制約 と content mode を aspect fit にする
-> 端末サイズによって横幅が広がりきらない

左右制約と content mode を scale to fit にする
-> 画像アスペクト比が維持されないで崩れる

Android だったら wrap_content 指定するだけなのにね。iOSは大変だ

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?