How to do anti-aliasing on rotated UIView (not UIImageView)

My problem is basically the same as this one . I have a UIView, and when I rotate it using CGAffineTransformMakeRotation, the edges are not smoothing.

I tried both adding a view as a preview in a larger UIView, and using a transparent border in the view, but none of them worked.

The OP of the above post decided to do this by creating an image with transparent borders in Photoshop and using UIImageView instead, but I can't do the same because the size of the UIView is determined at runtime.

Does anyone know of any solutions to this problem?

Please note that this is not a duplicate of this , because I am interested in using UIView and NOT UIImageView.

+7
source share
2 answers

Try setting UIViewEdgeAntialiasing = YES in your App-info.plist

+19
source

I solved this by creating a 3x3 px image in Photoshop. The central pixel of the image has the color that I need so that my background is, and the remaining pixels are transparent. Then I was able to use an instance of UIImageView and determine the size of the frame at runtime using the -stretchableImageWithLeftCapWidth: topCapHeight: method.

This solution, of course, does not work for UIViews, but in this way you can get around the "variable size" problem and use UIImageView instead.

0
source

All Articles