Draw Rectangle

suggest change

This does not stroke a rectangle. It installs the path as self.view.layer.mask, so only the inside of the path stays visible. The path is in the mask layer’s coordinates. The mask frame is 100 by 100 points, origin (50, 50).

CAShapeLayer *mask = [[CAShapeLayer alloc] init];

mask.frame = CGRectMake(50, 50, 100, 100);

CGFloat width = 100;

CGFloat height = 100;

CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, nil, 30, 30);

CGPathAddLineToPoint(path, nil, width, 30);

CGPathAddLineToPoint(path, nil, width, height);

CGPathAddLineToPoint(path, nil,30, height);

CGPathAddLineToPoint(path, nil, 30, 30);

CGPathCloseSubpath(path);


mask.path = path;

CGPathRelease(path);

self.view.layer.mask = mask;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents