2012-02-11 82 views
0

我使用我想要绘制固体circle.Here在drawRect: rect方法如何在用quartz2d绘图时在圆圈周围剪切矩形?

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 

    // Drawing with a white stroke color 
    CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0); 
    // And draw with a blue fill color 
    CGContextSetRGBFillColor(ctx, 0.0, 0.0, 1.0, 1.0); 
    // Draw them with a 2.0 stroke width so they are a bit more visible. 
    CGContextSetLineWidth(ctx, 2.0); 

    CGRect rrect = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height); 
    CGFloat radius = 30.0; 

    CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect); 
    CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect); 

    // Start at 1 
    CGContextMoveToPoint(ctx, minx, midy); 
    // Add an arc through 2 to 3 
    CGContextAddArcToPoint(ctx, minx, miny, midx, miny, radius); 
    // Add an arc through 4 to 5 
    CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, radius); 
    // Add an arc through 6 to 7 
    CGContextAddArcToPoint(ctx, maxx, maxy, midx, maxy, radius); 
    // Add an arc through 8 to 9 
    CGContextAddArcToPoint(ctx, minx, maxy, minx, midy, radius); 
    // Close the path 
    CGContextClosePath(ctx); 
    // Fill & stroke the path 
    CGContextDrawPath(ctx, kCGPathFillStroke); 
} 

我所采取的代码从苹果样品Quartzdemo制成UIView称为气泡的亚类。

我的问题是我正在绘制一个矩形内的圆,但我仍然看到矩形绘制的角落。

如何剪辑它们以便我只看到圆圈?请帮忙。我是新来的石英2D

这是我如何把它在我的我的控制器

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]; 
    Bubble *bub = [[Bubble alloc]initWithFrame:CGRectMake(210.0, 90.0, 60.0, 60.0)]; 
    [self.view addSubview:bub]; 
    [bub release]; 
} 

回答

1

viewDidLoad将这个是viewDidLoad中的response.It worked.i不要

bub.backgroundColor = [UIColor clearColor]; 
+0

谢谢我知道我错过了它。可以帮助我让这个圆圈看起来像一个在角落处有凸起的实心板。我也想添加一些光泽完成。 – Sreeram 2012-02-11 04:15:39