2011-08-24 6 views
2

코드에서 설정 한 사용자 정의 모양의 화살표가 있습니다. 제가하려는 것은 그라데이션으로 채우는 것입니다. 문제는 그라디언트가 아닌 사각형이 아닌 모양 (어두운 프레임 안의 공간)을 채우는 방법을 모른다는 것입니다. 어떤 아이디어?iOS에서 그라디언트로 CGPoints로 정의 된 도형을 채우는 방법은 무엇입니까?

//Define colours used in drawing 
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGColorRef lightColor = _lightColor.CGColor; 
CGColorRef darkColor = _darkColor.CGColor; 
CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 
              blue:0.2 alpha:0.5].CGColor; 

//Get label text size to help determine sizes for drawing 
CGSize textSize = [[_titleLabel text] sizeWithFont:[_titleLabel font]]; 

//Set shadow 
CGContextSaveGState(context); 
CGContextSetShadowWithColor(context, CGSizeMake(0, 2), 3.0, shadowColor); 

//Set arrow shape 
CGPoint rectangle_points[] = 
{ 
    CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y), 
    CGPointMake(textSize.width+10, _coloredBoxRect.origin.y), 
    CGPointMake(textSize.width+40, _coloredBoxRect.origin.y+20), 
    CGPointMake(textSize.width+10, _coloredBoxRect.origin.y+40), 
    CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y+40), 
    CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y), 
}; 
CGContextAddLines(context, rectangle_points, 6);  
CGContextSetFillColorWithColor(context, lightColor); 
CGContextFillPath(context); 

CGContextRestoreGState(context); 

//Draw dark frame for the arrow 
CGContextSetStrokeColorWithColor(context, darkColor); 
CGContextSetLineWidth(context, 1.0); 
CGContextSaveGState(context); 
draw1PxStroke(context, CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y), CGPointMake(textSize.width+10, _coloredBoxRect.origin.y), darkColor); 
draw1PxStroke(context, CGPointMake(textSize.width+10, _coloredBoxRect.origin.y+40), CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y+40), darkColor); 
draw1PxStroke(context, CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y), CGPointMake(_coloredBoxRect.origin.x, _coloredBoxRect.origin.y+40), darkColor); 
draw1PxStroke(context, CGPointMake(textSize.width+10, _coloredBoxRect.origin.y), CGPointMake(textSize.width+40, _coloredBoxRect.origin.y+20), darkColor); 
draw1PxStroke(context, CGPointMake(textSize.width+10, _coloredBoxRect.origin.y+40), CGPointMake(textSize.width+40, _coloredBoxRect.origin.y+20), darkColor);  
CGContextRestoreGState(context); 

답변

1

사과 샘플 응용 프로그램을 확인하십시오. "Polygons"섹션 (폴리곤 채우기)에서 정확히 필요한 부분이 있습니다. 예제에서와 같이 그리기 대신 그라디언트 그리기가 필요합니다. 그 레이디 언트 그라디언트도 샘플의 "그래디언트"섹션에 예시되어 있습니다. 이 도움이

http://developer.apple.com/library/ios/#samplecode/QuartzDemo/Introduction/Intro.html

희망, 블라드

관련 문제