我目前正在开发绘图应用程序,其中有一个 slider 可以增加和减少线宽。我只想做一件简单的事情,就是在 slider 前面画一个圆圈来表示宽度。我很容易做到,但它不是从中心增长和收缩,而是从顶部 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);
关于objective-c - 需要有关在 quartz-2d 中从中心增大和缩小圆的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12350855/