0

我目前正在开发绘图应用程序,其中有一个滑块来增加和减少线宽。我只想做一个简单的事情,就是在滑块前面放一个圆圈来表示宽度。我很容易做到了,但它没有从中心增长和收缩,它从顶部 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;
}

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

2

尝试

CGContextTranslateCTM(ctx, 12.5, 12.5);
CGRect circleRect = CGRectMake(-size/2., -size/2., size, size);
于 2012-09-10T11:40:50.783 回答