2012-08-15 4 views
0

아래는 핵심 그래픽에서 그려야 할 플래그입니다.그림자를 추가하는 방법, 핵심 그래픽

enter image description here

내가 할 것은 : 내가 끝나는하고 아래

enter image description here

입니다

Flag.m 
- (void)drawRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetLineWidth(context, 1.0); 

    CGContextMoveToPoint (context, 20, 10); 
    CGContextAddLineToPoint (context, 50, 10); 
    CGContextAddLineToPoint (context, 50, 90); 
    CGContextAddLineToPoint (context, 45, 90); 
    CGContextAddLineToPoint (context, 45, 95); 
    CGContextAddLineToPoint (context, 40, 92); 
    CGContextAddLineToPoint (context, 35, 90); 
    CGContextAddLineToPoint (context, 30, 92); 
    CGContextAddLineToPoint (context, 25, 95); 
    CGContextAddLineToPoint (context, 25, 90); 
    CGContextAddLineToPoint (context, 20, 90); 
    CGContextAddLineToPoint (context, 20, 10);  

    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); 
    CGContextFillPath(context); 

} 

내 질문 : 나는 그림자를 추가 할 수있는 방법

그래서 내 깃발은 접은 것 같아. 위의 붉은 깃발과 같은 꼬리 부분에 말려서 뒤틀려 짐

답변

1

이것은 비교적 단순화 된 버전입니다. 필자는 두 부분으로 구성하는 몇 가지 요점을 주석 처리했습니다. 꼬리 부분이 먼저 그려집니다. 그런 다음 주 리본이 위에 그려집니다. 좋은 그림자 효과는 다음과 같이 그릴 수 있습니다. [UIColor colorWithWhite:0.0 alpha:0.4]

약간 더 좋아지기를 원하면 주 영역의 아래쪽 몇 점을 그라디언트가있는 다른 사각형으로 그립니다. 마지막 직사각형을 그리기 전에 그림자를 반드시 끄십시오.

/*CGContextMoveToPoint (context, 20, 10); 
CGContextAddLineToPoint (context, 50, 10);*/ 
CGContextMoveToPoint (context, 48, 85); 
CGContextAddLineToPoint (context, 48, 90); 
CGContextAddLineToPoint (context, 45, 90); 
CGContextAddLineToPoint (context, 45, 95); 
CGContextAddLineToPoint (context, 40, 92); 
CGContextAddLineToPoint (context, 35, 90); 
CGContextAddLineToPoint (context, 30, 92); 
CGContextAddLineToPoint (context, 25, 95); 
CGContextAddLineToPoint (context, 25, 90); 
CGContextAddLineToPoint (context, 22, 90); 
CGContextAddLineToPoint (context, 22, 85); 
//CGContextAddLineToPoint (context, 20, 10); 
CGContextSetShadowWithColor(context, CGSizeMake(0, 5.), 3., [UIColor colorWithWhite:0 alpha:.4].CGColor); 
CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:.95 alpha:1].CGColor); 
CGContextFillPath(context); 
CGContextSetShadowWithColor(context, CGSizeMake(0, 2.), 1.5, [UIColor colorWithWhite:0 alpha:.3].CGColor); 
CGContextMoveToPoint (context, 20, 88); 
CGContextAddLineToPoint (context, 20, 10); 
CGContextAddLineToPoint (context, 50, 10); 
CGContextAddLineToPoint (context, 50, 88); 
CGContextFillPath(context); 
관련 문제