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?

有帮助吗?

解决方案

When you change the view scaling...:

self.layer.borderWidth = 2.0f / scaleFactor;

其他提示

It is the purpose of scaling and therefore its expected behaviour, that a 2px frame woudl be scaled up or down along with the remaining view.

You could have one view with the color of your frame and set a view ontop that is 4px/4px smaller and located at 2/2 which carries the remaining view just without the frame.

Then change the frame of the underlying (frame) view accordingly. Then scale the subview accordingly. Make sure it remains centered or still starts at (2/2).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top