0
我需要绘制很多线条。如何使用带有渐变的UIBezierPath绘制多点线条
我使用UIBezierPath绘制渐变线条和小5x10图案图像。 这里是下面的代码部分:
l1 = [UIBezierPath bezierPath];
[l1 moveToPoint:CGPointMake(76, 373)];
[l1 addLineToPoint:CGPointMake(940, 373)];
CAShapeLayer *pathLayer = [CAShapeLayer layer];
CGRect pathRect = self.view.frame;
path = l1;
pathLayer.frame = self.view.bounds;
pathLayer.bounds = pathRect;
pathLayer.geometryFlipped = NO;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"line1Pattern.png"]];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 8.0f;
pathLayer.opacity = 1;
[pathLayer setShadowOffset:CGSizeMake(0, 5)];
[pathLayer setShadowOpacity:0.5];
pathLayer.lineCap = kCALineCapRound;
pathLayer.lineJoin = kCALineJoinRound;
[pathArray addObject:pathLayer];
self.pathLayer = pathLayer;
如果该行是直的水平(如蓝色和红色) - 一切正常,结果是巨大的。 但是,如果我绘制倾斜的线,或者直线,然后平铺 - 结果不好。 这里是图像链接:左侧 - 我需要什么,右侧 - 什么亩结果:example
所以,据我所知 - 我需要旋转梯度来匹配线。但我无法想象如何实现这一点。
还有些线路可能有之字形像这个图:example
谁能帮我解决这个问题?或者建议绘制线条的另一种方式。 谢谢!
像CGGradientRef的渐变,并将其用于strokeColor? –
据我所知,可以使用CGContextReplacePathWithStrokedPath将路径转换为“中风”路径。然后用渐变填充它。 – bealex