Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is equivalent to center crop scale type of Android ImageView for iOS UIImageView?

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.

like image 594
Vinh Hung Nguyen Avatar asked Feb 07 '19 06:02

Vinh Hung Nguyen


People also ask

What is scale type in Android Studio?

ScaleType is used for uniformly scaling the image bounds to the ImageView. Android ImageView provides various types of ScaleType for different configurations. CENTER.

What is adjustViewBounds in Android?

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.


1 Answers

You should use .scaleAspectFill. In swift 4.2:

myImageView.contentMode = .scaleAspectFill
myImageView.clipsToBounds = true // If you want to crop
like image 67
qtngo Avatar answered Sep 29 '22 08:09

qtngo