2013-10-31 3 views
1

사용자가 화면에 두 개의 닫힌 타원을 그릴 수있는 간단한 그리기 루틴이 있습니다. 그라디언트의 "백분율"을 나타내는 내부 타원을 사용하여 그라데이션으로 타원을 채 웁니다. 즉 Th 구배는 외측 타원과 내측 타원 사이를 부드럽게 전환 할 것이다.Quartz2d 그래디언트 채우기

대화 형 그리기가 잘 작동합니다. 이제 그라디언트 만 입력하면됩니다.

의견이 있으십니까? 문서에서는 타원형이 아닌 완벽한 원형 그라데이션에 대해서만 설명합니다. 나는 그것이 가능 타원형 그라데이션 유무를 알 수없는

답변

5

_mike

enter image description here

. 그러나 원형을 타원형으로 변형 할 수 있습니다. 아이디어는 변형 된 좌표계에서 원을 그리는 것입니다. 코드의

샘플 :

Result of running code:

: 실행 코드의

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 
    CGContextScaleCTM(context, 1.0, 0.5); 
    CGGradientRef gradient; 
    CGColorSpaceRef colorspace; 
    CGFloat locations[2] = { 0.0, 1.0}; 
    NSArray *colors = @[(id)[UIColor whiteColor].CGColor, (id)[UIColor blueColor].CGColor]; 
    colorspace = CGColorSpaceCreateDeviceRGB(); 
    gradient = CGGradientCreateWithColors(colorspace, (CFArrayRef)colors, locations); 
    CGPoint startPoint, endPoint; 
    CGFloat startRadius, endRadius; 
    startPoint.x = 180; 
    startPoint.y = 180; 
    endPoint.x = 180; 
    endPoint.y = 180; 
    startRadius = 0; 
    endRadius = 100; 
    CGContextDrawRadialGradient (context, gradient, startPoint, startRadius, endPoint, endRadius, 0); 
    CGContextRestoreGState(context); 
} 

결과