简体   繁体   English

什么相当于Android ImageView for iOS UIImageView的中心裁剪比例类型?

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

我想问一下如何缩放图像以填充UIImageView但仍保持其宽高比,就像Android ImageViewcenterCrop缩放类型一样。

You should use .scaleAspectFill . 你应该使用.scaleAspectFill In swift 4.2: 在快速4.2:

myImageView.contentMode = .scaleAspectFill
myImageView.clipsToBounds = true // If you want to crop

You can set image view contentMode to UIView.ContentMode.scaleAspectFill . 您可以将图像视图contentMode设置为UIView.ContentMode.scaleAspectFill It is equivalent of Android scaleType centerCrop 它相当于Android scaleType centerCrop

Following are the main content modes of UIImageView: 以下是UIImageView的主要内容模式:

  • UIViewContentModeScaleToFill UIViewContentModeScaleToFill
  • UIViewContentModeScaleAspectFit UIViewContentModeScaleAspectFit
  • UIViewContentModeScaleAspectFill UIViewContentModeScaleAspectFill

the one to fill the whole imageview is 'ScaleAspectFill' plus you can also use 'clipsToBound' property as true so that it will crop the extra image which is out of imageview. 填充整个imageview的那个是'ScaleAspectFill',你也可以使用'clipsToBound'属性为true,这样它就会裁剪出超出imageview的额外图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM