I would like to ask how to scale an image to fill a UIImageView
but still keep its aspect ratio, just like the centerCrop
scale type of Android ImageView
does.
ScaleType is used for uniformly scaling the image bounds to the ImageView. Android ImageView provides various types of ScaleType for different configurations. CENTER.
When using adjustViewBounds you need to set either width or height of your image view to wrap content and the other to a fixed value. Then when you set adjustViewBounds to true, Android adjust your image based on the fixed height or width value you've set and keeps aspect ratio. The scale type plays also a role.
You should use .scaleAspectFill
. In swift 4.2:
myImageView.contentMode = .scaleAspectFill
myImageView.clipsToBounds = true // If you want to crop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With