毎回忘れるのでメモ
private func toumeiImage(size: CGSize) -> UIImage? { UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) guard let context = UIGraphicsGetCurrentContext() else { return nil } // 背景を透明で塗りつぶす context.setFillColor(UIColor.clear.cgColor) let rect = CGRect(origin: .zero, size: size) context.fill(rect) // 画像に変換する let toumeiImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() guard let image = toumeiImage else { return nil } return image }