iosobjective-cquartz-corecgaffinetransformscale

How to keep a consistent 2px border around a UIView when scaling it?


I have a custom UIView that is able to be scaled and rotated based on the values of a UISlider. Scaling is working well, it's simply:

self.myView.transform = CGAffineTransformScale(CGAffineTransformIdentity, sx, sy);

My UIView has a 2px border:

self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.borderWidth = 2.0f;

However when I scale the view larger the border also grows in size. How can I keep a consistent border that ignores the scale of the view?


Solution

  • When you change the view scaling...:

    self.layer.borderWidth = 2.0f / scaleFactor;