2011-02-08 3 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

그 이유는 ... –

관련 문제