Ios 石英岩芯绘制的图元很少
我想画一个带白色矩形(或几个矩形)的绿色圆圈。但是我不明白,如何使用Ios 石英岩芯绘制的图元很少,ios,iphone,objective-c,quartz-core,Ios,Iphone,Objective C,Quartz Core,我想画一个带白色矩形(或几个矩形)的绿色圆圈。但是我不明白,如何使用CGContext方法。这是我的密码。首先我画一个圆并填充它,然后我想在我的圆内画些别的东西。但是如果我使用相同的CGContextRef来绘制内部基本体,CGContextSetFillColor更改我的圆的颜色 - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextAddEllips
CGContext
方法。这是我的密码。首先我画一个圆并填充它,然后我想在我的圆内画些别的东西。但是如果我使用相同的CGContextRef
来绘制内部基本体,CGContextSetFillColor
更改我的圆的颜色
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, rect);
CGContextSetFillColor(ctx, CGColorGetComponents([self.color CGColor]));
CGContextFillPath(ctx);
switch (self.type)
{
case ETBRoundViewTypeBook:
{
CGRect bookRect = CGRectMake(CGRectGetMidX(rect) - 10, CGRectGetMidY(rect) - 12, 20, 24);
CGContextAddRect(ctx, bookRect);
CGContextSetFillColor(ctx, CGColorGetComponents([UIColor whiteColor].CGColor));
CGContextFillPath(ctx);
}
case ETBRoundViewTypeList:
{
break;
}
case ETBRoundViewTypeTick:
{
break;
}
default:
break;
}
}
编辑:通过将
CGContextSetFillColor
替换为CGContextSetFillColorWithColor
解决了问题。我刚刚尝试了这个方法,效果很好
-(void)drawRect:(CGRect)rect{
CGContextRef ctx =UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, rect);
CGContextSetFillColorWithColor(ctx, [UIColor greenColor].CGColor);
CGContextFillPath(ctx);
CGContextAddEllipseInRect(ctx, CGRectMake(30, 30, 40, 40));
CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor);
CGContextFillPath(ctx);
}
它似乎无法与
白色
一起使用<代码>红色可以工作。不,它也可以与白色一起工作。只需使用上面添加的drawRect代码创建UIView的子类,并通过将其添加到子视图来测试它。它可以工作。是否需要在我的自定义视图中添加子视图?是否可以只在一个视图中绘制UIView的子类?谢谢!我刚刚用CGContextSetFillColorWithColor
替换了CGContextSetFillColorWithColor