質問

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