CGContextFillEllipseInRect表现得很奇怪

时间:2012-03-17 20:25:15

标签: iphone objective-c ios ipad core-graphics

这是我的drawRect

- (void)drawRect:(CGRect)rect
{
    CGContextFillEllipseInRect(UIGraphicsGetCurrentContext(), self.bounds);
}

并且这个类的实例在下一个方面添加了一个子视图:

#define DOTS_SIZE 30

[self addSubview:[[VertexView alloc] initWithFrame:CGRectMake(anchor.x-DOTS_SIZE/2, anchor.y-DOTS_SIZE/2, DOTS_SIZE, DOTS_SIZE)]];

据我所知,我应该在视图边界中得到椭圆(圈出我的情况)。但我完全用矩形(方形)填充它。

顺便说一下,我已经记录了界限,它们的大小是30x30,所以我应该得到漂亮的小圆圈,但我得到正方形(T_T)

我会感谢任何建议!

1 个答案:

答案 0 :(得分:4)

问题是你必须在绘制椭圆之前进行一些设置。例如:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor); // Or any other color.
    CGContextFillEllipseInRect(ctx, self.bounds);
}

要使背景透明,您可以查看:Setting A CGContext Transparent Background

相关问题