我目前在绘图应用程序上工作,其中有一个滑块来增加和减少线宽。我只想做一件简单的事情,那就是在滑块前面画一个圆圈来表示宽度。我很容易做到这一点,但它不是从中心开始增长和缩小,而是从顶部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;
}


发布于 2012-09-10 19:40:51
试一试
CGContextTranslateCTM(ctx, 12.5, 12.5);
CGRect circleRect = CGRectMake(-size/2., -size/2., size, size);https://stackoverflow.com/questions/12350855
复制相似问题