LoginSignup
0
1

More than 3 years have passed since last update.

UIImageのContentModeについて

Posted at

UIImageにはContentModeという画像の見た目を変更するプロパティがあります。

ContentMode

Objective-C、 Swift
・AspectFit
・AspectFill
・ScaleToFit
の3種類でしたが、

SwiftUIでは
・ScaleToFit()
・ScaleToFill()
の2種類に変更されています。

ScaleToFill()

UIImage("拡張子を除外した画像名")
  .resizable()
  .ScaleToFit() 

AspectFill

UIImage("拡張子を除外した画像名")
   .resizable()
   .scaledToFill()

AspectFill + ClipToBounds

UIImage("拡張子を除外した画像名")
   .resizable()
   .scaledToFill()
   .frame(width: 400, height: 170)
   .clipped()

※ .resizable()がないと画像サイズが変更できないので必須。

参考

アスペクト比について(Qiita外に飛びます)
https://blog.fenrir-inc.com/jp/2011/05/uiviewcontentmode.html

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