I'm drawing a circle via a CAShapeLayer now I want that my circle is centered in the middle of the screen. The circles midpoint must be the middle point of my view.
This how I now try to do this:
- (void)_initCircle {
[_circle removeFromSuperlayer];
_circle = [CAShapeLayer layer];
_radius = 100;
// Create a circle
_circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0 * _radius, 2.0 * _radius) cornerRadius:_radius].CGPath;
// Center the shape in self.view
_circle.position = CGPointMake(CGRectGetMidX(self.view.bounds) - _radius,
CGRectGetMidY(self.view.bounds) - _radius);
_circle.fillColor = [UIColor clearColor].CGColor;
_circle.lineWidth = 5;
// Add to parent layer
[self.view.layer addSublayer:_circle];
}
The screenshot makes it clear that the circle isn't perfect in the mid because the label is centered in the middle of the screen ( center Y ). Where the blue and the black of the circle that should be equal to the label I think.
I don't see the calculation error, can someone help me?
EDIT:
Changing bounds to frame and letting the radius off gives me this result: