Deepraj Chowrasia Deepraj Chowrasia - 8 months ago 55
Objective-C Question

HOW TO ROTATE IMAGE in circular path

I want to

rotate image
(arrow) in circular path in
like this image. in circular path.

input image:

Arrow image

output after rotation:

Rotate arrow in CoreGraphics iOS


This will return rotated image

- (UIImage *)rotateImage:(UIImage *)image onDegrees:(float)degrees
    CGFloat rads = M_PI * degrees / 180;
    float newSide = MAX([image size].width, [image size].height);
    CGSize size =  CGSizeMake(image.size.width, newSide);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, image.size.width, newSide/2);
    CGContextRotateCTM(ctx, rads);
    CGRect r = CGRectMake(0,-[image size].height/2,image.size.width,image. size.height);
    [image drawInRect:r];
    UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
    return i;

    UIImage *arrowRotated180  = [self rotateImage:[UIImage imageNamed:@"arrowImage"] onDegrees:180];

    UIImage *arrowRotated90  = [self rotateImage:[UIImage imageNamed:@"arrowImage"] onDegrees:90];