Asim Habib Asim Habib - 1 year ago 161
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

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download