Asim Habib Asim Habib - 1 month ago 16
iOS Question

iOS layer position

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

arcLayer=[CAShapeLayer layer];
arcLayer.frame=self.circleView.frame;
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

Answer

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

CGRect frame = self.circleView.frame; 

frame.origin = CGPointZero;

arcLayer.frame=frame;

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