我正在尝试在UIView
. 我通过覆盖drawRect
我的子类中的方法来做到这一点UIView
。但是当显示视图时,我只看到 的backgroundColor
,view
但我没有看到我的形状被绘制在其中。
这是我-drawRect
方法中的代码
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);
正在绘制的数组如下:
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)]];