我试图填充形状的内部,但没有用。它只描边路径但不填充你好颜色。我已经用谷歌搜索了,但没有任何东西作为填充不起作用。指导我做错了什么。
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, pathi);
CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor);
CGContextSetFillColorWithColor(ctx, [UIColor yellowColor].CGColor);
CGContextSetLineWidth(ctx, 3.0);
CGContextSetLineCap(ctx, kCGLineCapSquare);
CGContextSetAllowsAntialiasing(ctx, NO);
// CGContextStrokePath(ctx);
CGContextDrawPath(ctx, kCGPathFillStroke);
编辑: pathi 的代码是
- (CGMutablePathRef)getPath {
if (self.shapeType == NOSHAPE) {
return nil;
}
[lineHeight removeAllObjects];
[linesArray removeAllObjects];
CGMutablePathRef path = CGPathCreateMutable();
switch (self.shapeType) {
case Rectangle_SHAPE:{
Line *l1 = [[Line alloc] initWithLineName:LineName_a_S
starttPoint:self.bound.origin
endPoint:CGPointMake(self.bound.size.width, self.bound.origin.y) scalingFactor:1.0
linePosition:LINE_DIRECTION_HORIZONTAL];
[lineHeight addObject:[NSNumber numberWithFloat:l1.lineLength]];
[linesArray addObject:l1];
Line *l2 = [[Line alloc] initWithLineName:LineName_c_S
starttPoint:CGPointMake(self.bound.size.width, self.bound.origin.y)
endPoint:CGPointMake(self.bound.size.width, self.bound.size.height) scalingFactor:1.0
linePosition:LINE_DIRECTION_VERTICAL];
[lineHeight addObject:[NSNumber numberWithFloat:l2.lineLength]];
[linesArray addObject:l2];
Line *l3 = [[Line alloc] initWithLineName:LineName_b_S
starttPoint:CGPointMake(self.bound.size.width, self.bound.size.height)
endPoint:CGPointMake(self.bound.origin.x, self.bound.size.height) scalingFactor:1.0
linePosition:LINE_DIRECTION_HORIZONTAL];
[lineHeight addObject:[NSNumber numberWithFloat:l3.lineLength]];
[linesArray addObject:l3];
Line *l4 = [[Line alloc] initWithLineName:LineName_d_S
starttPoint:CGPointMake(self.bound.origin.x, self.bound.size.height)
endPoint:self.bound.origin scalingFactor:1.0
linePosition:LINE_DIRECTION_VERTICAL];
[lineHeight addObject:[NSNumber numberWithFloat:l4.lineLength]];
[linesArray addObject:l4];
CGPathAddPath(path, NULL, [l1 getPath]);
CGPathAddPath(path, NULL, [l2 getPath]);
CGPathAddPath(path, NULL, [l3 getPath]);
CGPathAddPath(path, NULL, [l4 getPath]);
[l1 release];
[l2 release];
[l3 release];
[l4 release];
break;
}
default:
break;
}
return path;
}
我也在创造其他形状,路径也是以同样的方式制作的。Line类为我提供了起点和终点的线。请告诉我是否有我遗漏的东西。