2012-02-11 87 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