Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreGraphics FillPath And Stroke Path

I need to draw an hexagon and fill it with a color build with an Image as pattern. I did:

CGContextSaveGState(context);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:[UIImage imageNamed:@"patternerba.png"]] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(context, 3.0);
// drawing hexagon here...
CGContextStrokePath(context);
CGContextFillPath(context);
[[NSString stringWithFormat:@"Foo"] drawAtPoint:innerRect.origin withFont:[UIFont fontWithName:@"Helvetica" size:16]];
CGContextRestoreGState(context);

But depending from the order of CGContextStrokePath and CGContextFillPath, I get an hexagon bordered but not filled or filled but not bordered. How can I fix this?

like image 989
IssamTP Avatar asked Feb 22 '12 14:02

IssamTP


1 Answers

Try

CGContextDrawPath(context, kCGPathFillStroke);

Instead of

CGContextStrokePath(context);
CGContextFillPath(context);
like image 107
sch Avatar answered Nov 20 '22 20:11

sch