Ios 核心图形颜色上下文
所以。。。我有这个应用程序,它可以绘制形状,然后用户可以给它们上色。我制作了一个有4个形状的选项卡栏,当单击其中一个时,会绘制相应的形状。我从quartzDemo那里得到了绘画的灵感。所以我有一个shape通用类,然后是shape的shape\u name子类。这是广场的代码Ios 核心图形颜色上下文,ios,core-graphics,cgcontext,Ios,Core Graphics,Cgcontext,所以。。。我有这个应用程序,它可以绘制形状,然后用户可以给它们上色。我制作了一个有4个形状的选项卡栏,当单击其中一个时,会绘制相应的形状。我从quartzDemo那里得到了绘画的灵感。所以我有一个shape通用类,然后是shape的shape\u name子类。这是广场的代码 @implementation Square - (void)drawInContext:(CGContextRef)context { CGContextSetRGBStrokeColor(context, 0
@implementation Square
- (void)drawInContext:(CGContextRef)context {
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 1, 1);
CGContextAddLineToPoint(context, 1, 79);
CGContextAddLineToPoint(context, 79, 79);
CGContextAddLineToPoint(context, 79, 1);
CGContextAddLineToPoint(context, 1, 1);
CGContextClosePath(context);
CGContextStrokePath(context);
}
@end
当点击形状时,会出现一个颜色菜单,我想在点击菜单中的按钮时更改颜色。我怎样才能做到这一点
Ty。我建议在基本shape类中添加一个属性,如下所示:
@property(nonatomic,retain) UIColor* fillColor;
在菜单实现中,将属性值设置为用户选择的UIColor对象,并发送形状集NeedsDisplay。然后修改drawInContext:方法,如下所示:
CGContextSetFillColorWithColor(context, self.fillColor.CGColor);
// ... your current drawing code goes here
// replace the last line, with CGContextStrokePath(), with this:
CGContextDrawPath(context, kCGPathFillStroke);
我建议向基本形状类添加如下属性:
@property(nonatomic,retain) UIColor* fillColor;
在菜单实现中,将属性值设置为用户选择的UIColor对象,并发送形状集NeedsDisplay。然后修改drawInContext:方法,如下所示:
CGContextSetFillColorWithColor(context, self.fillColor.CGColor);
// ... your current drawing code goes here
// replace the last line, with CGContextStrokePath(), with this:
CGContextDrawPath(context, kCGPathFillStroke);