简体   繁体   中英

How to do antialiasing on a rotated UIView (NOT UIImageView)

My issue is basically the the same as this one . I have a UIView and when I rotate it usding CGAffineTransformMakeRotation, the edges are not being antialiased.

I tried both adding the view as a subview in a bigger UIView and using a transparent border on the view but none of these worked.

The OP of the aforementioned post solved this by making an image with transparent borders in photoshop and using a UIImageView instead but I cannot do the same because the size of the UIView is determined on runtime.

Does anyone know any solutions to this problem?

Note that this is not a duplicate of this post because I am interested in using a UIView and NOT a UIImageView.

尝试在App-info.plist中设置UIViewEdgeAntialiasing = YES

I solved this by creating a 3x3 px image in photoshop. The center pixel of the image has the color I wanted my background to have and the rest of the pixels are transparent. Then I was able to use an instance of UIImageView and to define the frame size at runtime by using the -stretchableImageWithLeftCapWidth:topCapHeight: method.

This solution, of course still does not work for UIViews but that way you can circumvent the "variable size" issue and use a UIImageView instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM