Questions tagged [cashapelayer]

CAShapeLayer is a special purpose CALayer subclass for drawing animatable shapes using cubic Bezier splines. It's a part of the QuartzCore framework and is available for both iOS (since iOS 3.0) and OS X (since OS X v10.6 "Snow Leopard").

CAShapeLayer is a special purpose CALayer subclass for drawing animatable shapes using cubic Bezier splines. It's a part of the framework and is available for both (since iOS 3.0) and (since OS X v10.6 "Snow Leopard").

The shapes is defined using the path property and can be both filled and stroked using the fillColor and strokeColor properties. Note that the backgroundColor property inherited from CALayer does not fill the shape. The path of the shape is animatable (but doesn't support implicit animations) but the appearance of the animation is undefined if the two paths have a different number of control points or segments.

There are several properties (animatable) to configure how the shape is stroked and filled. Using these properties the stroke can for example get a moving dashed patten (commonly called "marching ants").

The strokeStart and strokeEnd properties can also be used to only stroke part of the shape or to animate the shape being stroked. Both values go from 0.0 (beginning of path) to 1.0 (end of path) and values in between are interpolated along the path.


The page about Paths in the Quartz 2D Programming Guide is a great resource for learning more about creating paths, stroking, rounding and joining paths, filling paths and creating dash patterns.

951 questions
1
vote
1 answer

CAShapeLayer isn't centering in a uiview correctly

I'm trying to center a CAShapeLayer in the black box but for some reason, the shape always gets drawn way above the box like so: Here is the code that I'm using to draw the circle: var pulsatingLayer: CAShapeLayer! let shapeLayer = CAShapeLayer() …
Andy_V
  • 27
  • 5
1
vote
2 answers

Swift: addLine ignored in between two addArc calls when creating a path

This code does what I expect. It draws an arc, then adds a line 50 points wide from the top of that arc: path.move(to: .init(x: myX, y: myY)) path.addArc(withCenter: CGPoint(x: centerX, y: centerY), radius: radius1, startAngle: .pi, endAngle: (3 *…
RanLearns
  • 4,086
  • 5
  • 44
  • 81
1
vote
1 answer

Add Colour Gradient to Circular Progress Bar iOS

I am having difficulty adding a colour gradient to my circular progress bar My setup: Storyboard: ViewController with an empty view designated as the Class CircularProgressBar Custom class for the CircularProgressBar Steps Taken: I am able to…
Captain725
  • 73
  • 1
  • 7
1
vote
0 answers

CAShapeLayer stroke sometimes fall outside of filled region of the same path when using transforms

I have come across a problem where I try to set a simple path on a CAShapeLayer which in turn resides in a 3D transformed parent view/layer. For some of the transformations that I want to use the layer will stroke a very different path than what is…
LGP
  • 4,135
  • 1
  • 22
  • 34
1
vote
1 answer

Circle strokeWidth change animation without changing the circle radius

I have a few rects that I draw a circle in with UIBezierPath and CAShapeLayer. They should act like buttons, in which when they are tapped they are being selected and when a different button is tapped they are being deselected, where each of these…
1
vote
1 answer

How to fill only a part of the shape on CAShapeLayer

I am creating following shape with UIBezierPath and then draw it with CAShapeLayer as following. Then I can change CAShapeLayer fillColor property from shapeLayer.fillColor = UIColor.clear.cgColor to shapeLayer.fillColor = UIColor.blue.cgColor and…
S.Basnagoda
  • 671
  • 2
  • 8
  • 21
1
vote
1 answer

How to set CAShapeLayer 's strokeColor in swift

I want draw diagonal view. This is my code. override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let path = UIBezierPath() path.move(to: CGPoint.zero) path.addLine(to: CGPoint(x: 50, y: 50)) let view =…
oddK
  • 261
  • 4
  • 14
1
vote
2 answers

UIView has different cornerRadius than CAShapeLayer

I want to add a background view to a UITableViewCell, and also a CAShapeLayer to act as a border around the background view (I will need a dashed border). My problem is however, even though I set the cornerRadius of the view and the layer to the…
Balázs Vincze
  • 3,550
  • 5
  • 29
  • 60
1
vote
1 answer

How to properly copy CAShapeLayer in swift?

I'm trying to create copies of CAShapeLayer in swift but I'm getting a crash Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAShapeLayer copyWithZone:]: unrecognized selector sent to instance 0x282e87e60' which…
Lucas
  • 746
  • 8
  • 23
1
vote
2 answers

iOS Swift: How to merge two shapes into a solid color shape using UIBezierPath?

Hey~~ I am trying to draw a solid round dot with a rectangle handle on top of it. (backcolor: purple, forecolor: black) However, the shapes are all correct, but when I am coloring it, there is a gap at the shape overlapping area, which cannot be…
RainCast
  • 4,134
  • 7
  • 33
  • 47
1
vote
1 answer

Gradient Arc View Not Showing Correctly

i have a custom view that is a 85% of a circle ( Just Stroke ) with Gradient color . here is my code : class ProfileCircle:UIView { override func draw(_ rect: CGRect) { let desiredLineWidth:CGFloat = 4 // your desired value …
Arvin Rezaei
  • 818
  • 10
  • 25
1
vote
0 answers

Create custom Line graph with shadow using CAShapeLayer swift

I have modified Line graph of Minh Nguyen to some extend to show two lines one for systolic and othere for diastolic. The first image show the how the graph should look like and second image is what I have achieved. struct PointEntry { let…
Anirudha Mahale
  • 2,526
  • 3
  • 37
  • 57
1
vote
1 answer

Navigation view transition full screen to a view with corner radius

I am trying to create an app home screen animation from splash, like after launch screen completed (full)screen color transforms into an app logo background color. Currently below code kind of archive what I expected. But, that transformation…
Mathi Arasan
  • 869
  • 2
  • 10
  • 32
1
vote
1 answer

swift how to make gradient layer start at different position

I am coding an area graph, can't upload actual images so I draw an illustration. So I am using two layers, one layer to draw the area, another layer to draw the gradient. Here is the code for that: let area = CGMutablePath() let zero =…
Anna
  • 443
  • 9
  • 29
1
vote
1 answer

How to create an Eraser for CALayer.SubLayer Using a CAShapeLayer in Swift

I have been looking everywhere for the answer to a question that has been asked a ton of times. I have spent hours looking through SO and Google. There has to be an answer that isn't going to take a mountain moving effort. I am working on a vector…
jforward5
  • 93
  • 1
  • 12