Asim Habib
Asim Habib

Reputation: 381

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

Upvotes: 0

Views: 2874

Answers (2)

Zimes
Zimes

Reputation: 623

More concisely:

arcLayer.frame = self.circleView.bounds;

Upvotes: 1

Fahri Azimov
Fahri Azimov

Reputation: 11770

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!

Upvotes: 3

Related Questions