LoginSignup
0
1

More than 3 years have passed since last update.

UIButtonの画像をアスペクト比を維持してサイズ変更

Posted at

はじめに

UIButtonのサイズ変更に伴い,内部の画像サイズを変更したい場合の方法についてメモしました.

拡大方法

UIButtonいっぱいに画像を拡大.

button.imageView?.contentMode = .scaleAspectFit
button.contentHorizontalAlignment = .fill // オリジナルの画像サイズを超えて拡大(水平)
button.contentVerticalAlignment = .fill // オリジナルの画像サイズを超えて拡大(垂直)

縮小方法

画像の上下左右にマージンを取ることで縮小.

button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

参考

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