Iphone 填充路径的内部,保持线宽可见
我试图填补内部的形状,但没有用。它只笔划路径,但不填充hello颜色。我在谷歌上搜索过,但没有什么比填充不起作用更有效的了。告诉我我做错了什么Iphone 填充路径的内部,保持线宽可见,iphone,ios,core-graphics,quartz-graphics,cgpath,Iphone,Ios,Core Graphics,Quartz Graphics,Cgpath,我试图填补内部的形状,但没有用。它只笔划路径,但不填充hello颜色。我在谷歌上搜索过,但没有什么比填充不起作用更有效的了。告诉我我做错了什么 CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextAddPath(ctx, pathi); CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor); CGContextSetFillColorWithColor(
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类从起点和终点给我一条线。请告诉我是否有我遗漏的东西。我也建议用户Putz在其评论中建议: 存储路径,首先填充它(
CGContextFillPath
),更改笔划颜色,然后笔划(CGContextStrokePath
)它。我已经这样做了,效果很好。你看到了什么?只有红色的轮廓?(您实际看到的图像+预期的图像可能很有用)我尝试过,我能够使用相同的代码将边框和填充颜色分开。我将其用于您的“pathi”CGPathRef pathi=CGPathCreateWithEllipseInRect(CGRectMake(0,0,100,100),nil);现在我猜要么你的路径不是一个大的矩形,要么你正在使用一个更大的宽度大小值来隐藏你的填充颜色。@Puneet我也通过绘制矩形进行了检查,它正在工作,但不适用于我的路径。pathi在边距为1.5的整个矩形上喷水。我也尝试过默认宽度,但也不起作用。如果您想了解我是如何创建pathi的,我将与您共享代码。是的,请。在创建路径的地方共享代码为什么不使用
CGContextFillPath
和CGContextStrokePath
?然后你可以填充并绘制边界线。但要确保你是按这个顺序做的。