3

Possible Duplicate:
Any quick and dirty anti-aliasing techniques for a rotated UIImageView?

when a UIView is rotated, it's borders look incredible ugly. There's no antialiasing happening at all. Also if it's a UIImageView, no antialiasing happens when rotating the transform matrix. Is there a way to achieve smooth edges and smooth rotation of images?

Community
  • 1
  • 1

1 Answers1

18

For a UIImageView, add a one-pixel transparent border around the image. This will cause the edges of your image to be on the "inside", and because the inside pixels are interpolated when rotating, the borders will magically become antialiased. This also works for rotating UIButtons that have a custom image.

vocaro
  • 2,779
  • 2
  • 23
  • 16
  • 1
    For the longest time, I searched for a way to “add a one-pixel transparent border” around my UIImageView. I tried enlarging the `.frame` by 2 `CGFloat` s and varoious other methods until I figured you probably meant: add the border to the loaded UIImage (in my case constructed from a PNG file). – Raphael Schweikert Sep 06 '10 at 17:32
  • 2
    no I reckon he means set borderWidth on the view.layar (needs QuartzCore import) - see this post for more details: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/ – Anthony Main Sep 29 '10 at 23:36
  • Either way will work. You can add the border statically to the image itself, or add it dynamically to the UIImage at runtime, as described in my blog post. – vocaro Oct 06 '10 at 05:13
  • Worked for me. You are my hero of the day. – David Neiss Aug 16 '11 at 03:43