Skip to content

Instantly share code, notes, and snippets.

@DuncanMC
Created March 12, 2014 20:02
Show Gist options
  • Save DuncanMC/9515158 to your computer and use it in GitHub Desktop.
Save DuncanMC/9515158 to your computer and use it in GitHub Desktop.
Creating a bezier path
UIBezierPath *aPath = [UIBezierPath UIBezierPath];
[aPath moveToPoint: CGPointMake(0, 0);
[aPath addLineToPoint: CGPointMake(0, 200)];
[aPath addLineToPoint: CGPointMake(200, 200)];
[aPath addLineToPoint: CGPointMake(200, 0)];
[[aPath closePath];
@DuncanMC
Copy link
Author

And then to create a shape layer from that:

//Create a bezier path that's a square 200 x 200 points
UIBezierPath *aPath = [UIBezierPath UIBezierPath];
[aPath moveToPoint: CGPointMake(0, 0);
[aPath addLineToPoint: CGPointMake(0, 200)];
[aPath addLineToPoint: CGPointMake(200, 200)];
[aPath addLineToPoint: CGPointMake(200, 0)];
[[aPath closePath];

Now create a shape layer
CAShapeLayer* aLayer = [CAShapeLayer layer];
aLayer.bounds = aView.layer.bounds;
aLayer.path = aPath.CGPath;

//Fill the shape with white
aLayer.fillColor = [UIColor whiteColor].CGColor;

//Add the new shape layer as a sublayer of our view's layer.
[aView.layer addSublayer: aLayer]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment