Objective c 需要有关成长和发展的帮助;石英-2d中的中心收缩圆

Objective c 需要有关成长和发展的帮助;石英-2d中的中心收缩圆,objective-c,ios,quartz-2d,Objective C,Ios,Quartz 2d,我目前正在绘制应用程序,其中有一个滑块,以增加和减少线宽。我只想做一件简单的事情,在滑块前面画一个圆圈来表示宽度。我很容易做到这一点,但它并没有从中心开始变大变小,而是从顶部x,y开始变大变小,这是代码 - (UIImage *)circleOnImage:(int)size { UIGraphicsBeginImageContext(CGSizeMake(25, 25)); CGContextRef ctx = UIGraphicsGetCurrentContext();

我目前正在绘制应用程序,其中有一个滑块,以增加和减少线宽。我只想做一件简单的事情,在滑块前面画一个圆圈来表示宽度。我很容易做到这一点,但它并没有从中心开始变大变小,而是从顶部x,y开始变大变小,这是代码

- (UIImage *)circleOnImage:(int)size
{
    UIGraphicsBeginImageContext(CGSizeMake(25, 25));

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    [[UIColor blackColor] setFill];

        CGContextTranslateCTM(ctx, 12, 12);//also try to change the coordinate but didn't work

    CGRect circleRect = CGRectMake(0, 0, size, size);

    CGContextFillEllipseInRect(ctx, circleRect);

    UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return retImage;
}

试试看

CGContextTranslateCTM(ctx, 12.5, 12.5);
CGRect circleRect = CGRectMake(-size/2., -size/2., size, size);