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

时间:2016-12-27 20:50:50

标签: ios imageview scale

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

我如何在IOS中做同样的事情?我是IOS的新手,我使用的是swift 3,我没有找到类似的类似东西。

1 个答案:

答案 0 :(得分:1)

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

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

相关问题