2011-07-05 4 views
1

私のiPhoneアプリのカスタム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)); 
} 
関連する問題