blancos
blancos

Reputation: 1614

How to draw an ellipse using UIBezierPath at an angle?

I am drawing ellipse using following UIBezierPath method:

UIBezierPath *bpath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];

This gives me something like below:

enter image description here

But I want to draw ellipse at an angle like below:

enter image description here

I know one solution is to rotate the UIView. But I cannot do this because same view contain other bezier paths. So I want to know if there is any way to draw this ellipse at an angle?

Upvotes: 2

Views: 2358

Answers (1)

Rob Napier
Rob Napier

Reputation: 299345

Often the easiest way is to put this on a CAShapeLayer and then rotate the layer. The math for that tends to be very simple (particularly if you want to change the transform later). But you can also just rotate the path directly before drawing it by creating a rotation transform (CGAffineTransformMakeRotation) and using -applyTransform: to modify the path.

Upvotes: 8

Related Questions