title: Rotate UIImage custom degree
body: <p>I want to rotate an UIImage (not UIImageView) in custom degree
  I followed <a href="https://stackoverflow.com/questions/917713/uiimage-rotation-custom-degrees">this post</a> but it didn't work for me.</p>
  
  <p>Anyone can help? Thanks.</p>
  
  <p>UPDATE:
  The code below does some of the job, but I lose some of the image after rotating it:</p>
  
  <p><img src="https://i.stack.imgur.com/9G0qc.jpg" alt="enter image description here"></p>
  
  <p>What should I change to get it right? (btw the yellow color in the screenshots is my UIImageView bg)</p>
  
  <pre><code>- (UIImage *) rotate: (UIImage *) image
  {
      double angle = 20;
      CGSize s = {image.size.width, image.size.height};
      UIGraphicsBeginImageContext(s);
      CGContextRef ctx = UIGraphicsGetCurrentContext();
      CGContextTranslateCTM(ctx, 0,image.size.height);
      CGContextScaleCTM(ctx, 1.0, -1.0);
  
      CGContextRotateCTM(ctx, 2*M_PI*angle/360);
      CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage);
      UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return newImage;
  
  }
  </code></pre>