2014-03-31 40 views
1

我一直試圖剪輯我的視圖,使其指向右側,但由於某種原因,它不工作。CGContextClip在drawRect不工作

以下是我在代碼的drawRect:

CGContextRef ctx = UIGraphicsGetCurrentContext(); 

CGContextMoveToPoint(ctx, width - 20.0, 0.0); 
CGContextAddLineToPoint(ctx, width, height/2.0); 
CGContextAddLineToPoint(ctx, width - 20.0, height); 

[[UIColor blackColor] setStroke]; 
CGContextStrokePath(ctx); 

CGContextClip(ctx); 

我只是把描邊路徑,看看它的工作。 筆畫工作正常,但CGContextClip()只是不會工作(沒有筆畫功能)來挽救我的生命。

請幫助我!提前致謝!

+0

你要像黃金三角一三角形? –

+0

是的,我正在嘗試製作一個帶有向右箭頭的矩形,就像那些允許您在向下鑽取界面中導航的東西。 – BridgeTheGap

+0

因此,您只需使用'CGContext'繪製一個矩形。你爲什麼裁剪路徑? –

回答

0

請使用CoreGraphics

-(void) drawRect:(CGRect)rect { 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGContextMoveToPoint(ctx, CGRectGetMinX(rect), CGRectGetMinY(rect)); 
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect)/2, CGRectGetMaxY(rect)); 
    CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMinY(rect)); 
    [[UIColor redColor] setFill]; 
    CGContextFillPath(ctx); 
} 
+0

謝謝。我從你的評論中得到了提示,所以我把它整理出來:)非常感謝 – BridgeTheGap

+0

的歡迎。快樂編碼 –