我用下面的代碼爲填充路徑viewDidLoad
它的作品完美CGContextFillPath(上下文)創建一個行
UIGraphicsBeginImageContext(_drawingPad.frame.size);
CGContextRef context1 = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context1, 300, 300);
CGContextAddLineToPoint(context1, 400, 350);
CGContextAddLineToPoint(context1, 300, 400);
CGContextAddLineToPoint(context1, 250, 350);
CGContextAddLineToPoint(context1, 300, 300);
CGContextClosePath(context1);
//CGContextStrokePath(context1);
CGContextSetFillColorWithColor(context1, [UIColor redColor].CGColor);
CGContextFillPath(context1);
CGContextStrokePath(context1);
也是我創建一個線的時候開始接觸.. 但將填充路徑時被刪除在創建線條之前擦除。
OP * *在當前圖形上下文中創建路徑。您的代碼首先創建一個單獨的CGMutablePathRef,然後將其添加到當前上下文中。這當然也是有效的,但是(正如我所假設的)獨立於OP的問題。我當然可能是錯的:-) –