在 ImageView 中缩放图像(缩放 x、y)- IOS

Scale an Image in ImageView (Scale x,y) - IOS

我通常使用 scaleX 和 scaleY 属性缩放 Android 中 imageView 的图像。

如何在 IOS 中执行相同的操作?我是 IOS 的新手,我正在使用 swift 3,但我没有找到任何类似的东西。

如果您需要按比例缩放图像,以下代码可能适合您:

if let cgImage = imageView.image?.cgImage, let orientation = imageView.image?.imageOrientation {
    imageView.image = UIImage(cgImage: cgImage, scale: newScale, orientation: orientation)
}

但是,如果您只想以与原始图像不同的尺寸显示它,您应该使用呈现它的 UIImageView 的尺寸来控制图像的尺寸。为确保图像随视图大小正确缩放,请查看 UIImageView.contentMode 属性:https://developer.apple.com/reference/uikit/uiview/1622619-contentmode