2011-07-05 2 views
1

내 iPhone app 사용자 정의 UIView 클래스에서이 drawRect 메소드의 문제점은 무엇입니까? 색깔이있는 원을 그려야하지만 적절한 너비와 높이의 검은 색 사각형을 그립니다.iPhone App - 내 CGContext 서클이 검은 색 사각형처럼 보이는 이유는 무엇입니까?

- (void)drawRect:(CGRect)rect { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(context, 2.0); 
    UIColor *c = [UIColor redColor]; 
    const CGFloat *components = CGColorGetComponents([c CGColor]); 
    CGFloat red = components[0]; 
    CGFloat green = components[1]; 
    CGFloat blue = components[2]; 
    CGFloat al = components[3];  
    CGContextSetRGBFillColor(context, red, green, blue, al); 
    CGContextFillEllipseInRect(context, CGRectMake(x, y, width, width)); 
} 

답변

0

이 시도 :이 잘 작동

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGContextAddEllipseInRect(ctx, CGRectMake(x, y, width, width)); 
    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor redColor] CGColor])); 
    CGContextFillPath(ctx); 
} 
0

희망을.

- (void)drawRect:(CGRect)rect { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(context, 2.0); 
    CGContextSetFillColorWithColor(context , [UIColor redColor].CGColor; 
    CGContextFillEllipseInRect(context, CGRectMake(x, y, width, width)); 
} 
관련 문제