答案 0 :(得分:1)
尝试此操作,传入包含您需要的所有子视图的基本视图:
func createImage(from aView:UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(CGSize(width: aView.frame.width, height: aView.frame.height), true, 0)
aView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}