Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Scale context from center in Core Graphics?

I'm drawing with Core Graphics and I need to scale down the current context. I use the CGContextScaleCTM function but this use de origin and not the center. How can I make scale from center?

like image 732
alejandromp Avatar asked Dec 18 '25 14:12

alejandromp


1 Answers

Change constant as required.

let percentScale : CGFloat = 0.8
context.translateBy(x: rect.size.width * (1.0 - percentScale) * 0.5, y: rect.size.height * (1.0 - percentScale) * 0.5)
context.scaleBy(x: percentScale, y: percentScale)
// ...draw into context
like image 125
Rowan Avatar answered Dec 20 '25 05:12

Rowan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!