需要有关种植和增长的帮助从石英-2d的中心收缩圆圈

时间:2012-09-10 11:34:57

标签: objective-c ios quartz-2d

我目前正在制作绘图应用,其中有一个滑块可以增加和减少线宽。我只是想做一个简单的事情,滑块前面的圆圈呈现宽度。我很容易做到这一点,但它没有增长和缩小中心,它从顶部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;
}

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:2)

尝试

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