Ios 使用Objective-C更改椭圆上的填充颜色

Ios 使用Objective-C更改椭圆上的填充颜色,ios,core-graphics,Ios,Core Graphics,我正在重写drawRect方法以绘制椭圆 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor mainColorYellow].CGColor); CGRect rectangle = CGRec

我正在重写drawRect方法以绘制椭圆

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor mainColorYellow].CGColor);

CGRect rectangle = CGRectMake(0.0, 2.0, rect.size.width , rect.size.height - 4.0);

CGContextAddEllipseInRect(context, rectangle);

CGContextStrokePath(context);
}


如何更改椭圆上的填充颜色?我尝试使用
CGContextSetFillColorWithColor(CGContextRef c,CGColorRef color)
,但没有结果

有两种不同的操作,填充和笔划。笔划是边界,填充是内部。你只是在边界上。可以独立控制填充和边框颜色。但是,您必须显式地呈现这两个对象。例如:

[[UIColor yellowColor] setFill];
[[UIColor blackColor] setStroke];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0.0, 2.0, rect.size.width , rect.size.height - 4.0)];
path.lineWidth  = 2.0;        
[path fill];
[path stroke];
注意,我用更现代的石英编写了代码。上下文是隐含的。希望有帮助。

只需添加以下内容:

    CGContextFillEllipseInRect(context, rectangle);

你只是在走这条路。你需要把它填满。