截图UIImageView我只需要图像IOS

在我的iOS应用程序,我正在采取UIImageView的屏幕截图。 如附件照片所示,非常完美。 但在这里,我已经采取UIImageView content mode 方面适合 。 我已经使用这个代码。

 func captureView() -> UIImage { UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false,UIScreen.mainScreen().scale)//add this line let context: CGContextRef = UIGraphicsGetCurrentContext()! self.backView.layer.renderInContext(context) let img: UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return img } 

我只需要Image的快照,而不是ImageView。 帮我解决这个问题。 在这里输入图像说明

试试这个代码:

 func captureView() -> UIImage() { UIGraphicsBeginImageContext(YourimageView.frame.size) YourimageView.layer.renderInContext(UIGraphicsGetCurrentContext()!) let img = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil) return img }