// // ViewController.swift // UIGraphicsImageRendererIssue // // Created by Thibault POUJAT on 18/08/2025. // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Create a layer filled with a regular UIColor let layerWithRegularUIColor = CAShapeLayer() layerWithRegularUIColor.frame = CGRect(x: 50, y: 100, width: 100, height: 100) layerWithRegularUIColor.path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 100, height: 100)).cgPath layerWithRegularUIColor.fillColor = UIColor.red.cgColor view.layer.addSublayer(layerWithRegularUIColor) // Create a layer filled with a UIColor(patternImage:) let layerWithUIGraphicsImageRendererColor = CAShapeLayer() layerWithUIGraphicsImageRendererColor.frame = CGRect(x: 200, y: 100, width: 100, height: 100) layerWithUIGraphicsImageRendererColor.path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 100, height: 100)).cgPath layerWithUIGraphicsImageRendererColor.fillColor = UIColor.yellow.patternStripes(color2: UIColor.green).cgColor view.layer.addSublayer(layerWithUIGraphicsImageRendererColor) view.backgroundColor = UIColor.lightGray // Those two layers are displayed correctly on iOS 18.2 and earlier // The second one is a pattern color created with UIGraphicsImageRenderer, and is not displayed as expected for iOS 26.0 (23A5318f) // Instead of the expected pattern, we get a white/blank rectangle. } } extension UIColor { func patternStripes(color2: UIColor = .clear, barThickness: CGFloat = 5.0) -> UIColor { let dim: CGFloat = barThickness * 2.0 * sqrt(2.0) let img = UIGraphicsImageRenderer(size: .init(width: dim, height: dim)).image { context in // What we do in there does not affect the main issue : we have a blank view with iOS 26 // rotate the context and shift up context.cgContext.rotate(by: CGFloat.pi / 4.0) context.cgContext.translateBy(x: 0.0, y: -2.0 * barThickness) let bars: [(UIColor, UIBezierPath)] = [ (self, UIBezierPath(rect: .init(x: -0.0, y: 0.0, width: dim * 2.0, height: barThickness * 1.5))), (color2, UIBezierPath(rect: .init(x: -0.0, y: barThickness * 1.5, width: dim * 2.0, height: barThickness * 0.5))) ] bars.forEach { $0.0.setFill(); $0.1.fill() } // move down and paint again context.cgContext.translateBy(x: 0.0, y: 2.0 * barThickness) bars.forEach { $0.0.setFill(); $0.1.fill() } } return UIColor(patternImage: img) } }