2011-02-08 41 views
1

所以...我有這個應用程序繪製形狀,然後用戶可以爲它們着色。我做了一個有4個形狀的tabbar,當點擊一個時,相應的形狀被繪製出來。我從quartzDemo中獲取了繪圖的想法。所以我有一個形狀通用類,然後shape_name的形狀子類。這是Square的代碼。核心圖形顏色上下文

@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提前。

回答

4

我建議增加一個屬性到您的基本形狀類是這樣的:

@property(nonatomic,retain) UIColor* fillColor; 

在你的菜單中執行屬性的值設置爲您的用戶選擇的對象的UIColor和發送形狀setNeedsDisplay。然後修改您的drawInContext:方法如下:

CGContextSetFillColorWithColor(context, self.fillColor.CGColor); 
// ... your current drawing code goes here 
// replace the last line, with CGContextStrokePath(), with this: 
CGContextDrawPath(context, kCGPathFillStroke); 
+0

那樣做了......謝謝 – 2011-02-09 11:20:59