How do I use CAShapeLayer to draw a line that has both a border color, border width and fill color?
Here's what I've tried, but it's only ever blue...
self.lineShape.strokeColor = [UIColor blueColor].CGColor;
self.lineShape.fillColor = [UIColor greenColor].CGColor;
self.lineShape.lineWidth = 100;
self.lineShape.lineCap = kCALineCapRound;
self.lineShape.lineJoin = kCALineJoinRound;
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:self.lineStart];
[path addLineToPoint:self.lineEnd];
self.lineShape.path = path.CGPath;
In Swift 3. an extension method of
UIView
.If you set the layer's
fillColor
property to something other thannil
or transparent, the layer will fill its path.If you set the layer's
lineWidth
to a number larger than zero and you set itsstrokeColor
to something other thannil
or transparent, the layer will stroke its path.If you set all of those properties, the layer will fill and stroke its path. It draws the stroke after the fill.
The layer's path must actually enclose some area in order for it to fill anything. In your post, you set the path like this:
That path contains a single line segment. It doesn't enclose any area, so the layer has nothing to fill.