我重写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);