我有一个形状,它有一些 UIBezierPaths 我试图在我的视图中绘制它们并没有显示出来。你能告诉我我做错了什么吗?
// Function to perform custom drawing.
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
for (Stroke* stroke in letter.strokes)
{
if (letter.strokes[letter.currentStroke] == stroke)
{
[stroke.path stroke];
}
else
{
[stroke.path strokeWithBlendMode:kCGBlendModeNormal alpha:0.5f];
}
[self setNeedsDisplayInRect:stroke.path.bounds];
}
}
也不起作用的新代码:
for (Stroke* stroke in letter.strokes)
{
UIBezierPath* path = stroke.path;
[[UIColor blackColor] setStroke];
[[UIColor redColor] setFill];
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(currentContext);
CGContextTranslateCTM(currentContext, 50, 50);
path.lineWidth = 5;
if (letter.strokes[letter.currentStroke] == stroke)
{
[path fill];
[path stroke];
}
else
{
[stroke.path strokeWithBlendMode:kCGBlendModeNormal alpha:0.5f];
}
[self setNeedsDisplayInRect:stroke.path.bounds];
CGContextRestoreGState(currentContext);
}