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

Unexpected StrokeEnd for CAShapeLayer

I'm drawing a circle using a CAShapeLayer and for some reason, the stroke will only be drawn at 25% intervals. For instance, setting the StrokeEnd to 0.4 draws the stroke to 50% of the circle. How can I draw the stroke of a CAShapeLayer to the…
froggomad
  • 1,747
  • 2
  • 17
  • 40
1
vote
2 answers

How I can create this circular shape in iOS Swift4?

I have to create this shape like the below image in a UIView. But I am not get any idea how to draw this shape. I am trying to draw this shape using UIBezierPath path with CAShapeLayer the circular line draw successfully but I am unable to draw the…
Tapas_ios
  • 73
  • 6
1
vote
3 answers

How to change stroke color of CAShaperLayer on button click

I am have create some custom layer and added on UIView ,i have two CAShaper Layer but i am just showing only one example here hexBorderOtline = CAShapeLayer() hexBorderOtline.name = "dhiru_border_hidden" hexBorderOtline.path =…
Dhiru
  • 3,040
  • 3
  • 25
  • 69
1
vote
0 answers

How do I add a glow effect around the half circle cashapelayer?

I have a circular cashapelayer progress bar, I want to add a glow effect along the path. I have try using shadowcolor, shadowoffset and shadowpath and didnt get the expected result. let circlePath = UIBezierPath(arcCenter: .zero, radius:…
Shen Yi
  • 21
  • 4
1
vote
1 answer

How to re-draw line connected between moveable two UIView

I would like to re-draw the line between two movable UIView, depending on the position of UIView. So I found this. However, this method uses "Pan Gesture" to re-draw lines, depending on the position of the gesture. Also found are setNeedsDisplay(),…
bakuiseok
  • 41
  • 1
  • 10
1
vote
0 answers

Is this the proper way to set a frame for a CAShapeLayer?

My goal is to get shapes I can drag abound the view, but first am trying to figure out if this is the correct way to set the frame so that a CAShapeLAyer's frame is not all zeros and so I can later drag it with touch events. Below is the code in my…
Rillieux
  • 587
  • 9
  • 23
1
vote
1 answer

Why is the drawn UIBezierPath positioned in the bottom right without specifying a central position in CAShapeLayer?

I tried to centralize UIBezierPath in a superview, but the UIBezierPath is positioned at the bottom right, not at the center. I set the value of anchorPoint to (0.5, 0.5), position self.view.center or self.view.frame.width / 2, but the UIBezierPath…
bakuiseok
  • 41
  • 1
  • 10
1
vote
0 answers

Adding UIBezierPath to CAShapeLayer in iOS Swift

I am trying to add a bezierPath as a sublayer of a view. Following is my code let arrPoints = Array(picture.points) let bezierPath = UIBezierPath() bezierPath.move(to: CGPoint(x: (arrPoints.first?.x.cgFloat()!)! * scaleX, …
Vaibhav Jhaveri
  • 1,579
  • 3
  • 28
  • 53
1
vote
1 answer

Swift - How to make animated arrow point in right direction?

I have two buttons which when connected, show a line with an animated arrow to show that they are connected.The issue is the arrow it self is not rotating appropriately to point in the right direction when animated. How can I rotate the arrow to…
STerrier
  • 3,755
  • 1
  • 16
  • 41
1
vote
1 answer

CAShapeLayer doesn't show up

I am trying to add a CAShapeLayer to a view. But when I add the customView to ViewCOntroller's View, the shapeLayer doesn't show up. Capturing hierarchy shows that the layer doesn't even get inserted to the View. Here is the code: override class var…
user10065208
1
vote
2 answers

How to intersect CAShapeLayers in iOS

I have a plus (+) sign that's currently colored in blue but I would like to make it transparent so that the user can see the background. The plus layer is added to a bigger view. Setting the plus layer to clear color doesn't solve the problem. class…
Cesare
  • 9,139
  • 16
  • 78
  • 130
1
vote
1 answer

Animate CAShapeLayer's path by transform.scale property

I'm trying to animate scale of CAShapeLayer that has a circle path (playground compatible): import UIKit import PlaygroundSupport let view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 200, height: 200))) view.backgroundColor =…
pacification
  • 5,838
  • 4
  • 29
  • 51
1
vote
1 answer

CAShapelayer animate fill color from bottom

I have a CAShapelayer that's made from a bezier path, but the path is complex and not just a square. I need to animate the shapelayer fill color to Yellow starting from the bottom of the curve and up (over y axis). (after the layer already attached…
Curnelious
  • 1
  • 16
  • 76
  • 150
1
vote
2 answers

CAShapeLayer fill color will stay White

I can clearly see my line, with the right stroke color, and the line is being drawn correctly, but no matter what, the fill color stay white. I have added this layer to another UIView subclass (custom view ) let shapeLayer = CAShapeLayer() …
Curnelious
  • 1
  • 16
  • 76
  • 150
1
vote
1 answer

Change CAShapeLayer stroke position

I have a collectionviewcell cell and I am adding a CAShapeLayer to give my frontImageView a half border. The code I have now successfully creates a half border but not where I want it. Setting stokeEnd=0.5 creates a half border on the bottom of my…
Peter
  • 1,053
  • 13
  • 29