私は、同様のタスクを持っていたし、このコードを使用:
func getResultImage() throws -> (image: UIImage, path: URL) {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
defer {
UIGraphicsEndImageContext()
}
drawHierarchy(in: self.bounds, afterScreenUpdates: true)
guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
throw ImageEditorViewError.noImageGenerated
}
guard let data = UIImagePNGRepresentation(image) else {
throw ImageEditorViewError.noDataRepresentation
}
let writePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("Image.png")
try data.write(to: writePath)
return (image, writePath)
}
は、このコードは、あなたのコンテナビュー内であることを、仮定私の仕事のために特異的であったとしてあなたは、writePahtとの一部を削除することができますあなたの中にいくつかのビューステッカーがあります。
これをチェックしてください。http://stackoverflow.com/questions/30696307/how-to-convert-a-uiview-to-a-image – iOS