I'm trying to draw a hexagon in a UIView
. I do this by overriding the drawRect
method in my subclass of UIView
.
But when the view is shown I only see the backgroundColor
of the view
but I don't see my shape being drawn in it.
This is the code in my -drawRect
method
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents([_fillColor CGColor]));
NSArray *points = _hex.points;
CGPoint point = [points[0] CGPointValue];
CGContextMoveToPoint(context, point.x, point.y);
for (int i = 1; i < [points count]; i++){
CGContextAddLineToPoint(context, point.x, point.y);
}
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFill);
The array that is being drawn is the following:
NSMutableArray *mutablePoints = [NSMutableArray arrayWithCapacity:6];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(40, 0)]];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(59, 0)]];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(68.5, 16.4544)]];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(59, 32.9089)]];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(40, 32.9089)]];
[mutablePoints addObject:[NSValue valueWithCGPoint:CGPointMake(30.5, 16.4544)]];