let renderer = UIGraphicsImageRenderer(size: CGSize(width: 500, height: 500))
let image = renderer.image { context in
let size = renderer.format.bounds.size
UIColor.red.setFill()
context.cgContext.fillEllipse(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let x = 300 //center
let y = 100 //center
let w = 200
let h = 60
let r = 5.41 //radians
UIColor.white.setFill()
context.cgContext.fill(CGRect(x: x - w / 2, y: y - h / 2, width: w, height: h))
}
The result is like this:
How can I rotate my white rectangle with rotation center in the middle of the rectangle before it is drawn in context?