Asim Habib Asim Habib - 3 months ago 50
iOS Question

iOS layer position

I want to draw a layer on a view. for that i write this code.

arcLayer=[CAShapeLayer layer];
arcLayer.backgroundColor = [UIColor purpleColor].CGColor;
[self.circleView.layer addSublayer:arcLayer];

but this the position of layer is not exact on the view as you can see in the following image. the green one is circleView and the purple one is arc layer.

enter image description here


You have a problem on this line: arcLayer.frame=self.circleView.frame;. Change that line to:

CGRect frame = self.circleView.frame; 

frame.origin = CGPointZero;


This will solve your problem. You just forgot to set origin of your layer to CGPointZero or whatever position. Good Luck!