-2

I want to draw triangle with rectangle like this image.

enter image description here

But I can draw like this shape using this code. enter image description here

CAShapeLayer *mask = [[CAShapeLayer alloc] init];
mask.frame = imgTest.layer.bounds;
CGFloat width = imgTest.layer.frame.size.width;
CGFloat height = imgTest.layer.frame.size.height;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 30, 0);
CGPathAddLineToPoint(path, nil, width, 0);
CGPathAddLineToPoint(path, nil, width, height);
CGPathAddLineToPoint(path, nil, 0, height);
CGPathAddLineToPoint(path, nil, 30, 0);
CGPathCloseSubpath(path); mask.path = path;
CGPathRelease(path);
imgTest.layer.mask = mask;

So how can I draw like first image shape?

chedabob
  • 5,835
  • 2
  • 24
  • 44
hmlasnk
  • 1,160
  • 1
  • 14
  • 33
  • 1
    Turn your computer upside down. But seriously - I think if you just try to understand the code you have, you should be able to change it easily. – rghome Jan 06 '16 at 10:44
  • @rghome Yes. I did some research about CAShapeLayer but I couldn't understand as how to set CGPathMoveToPoint and CGPathAddLineToPoint. After see the bellow answer I can able to understand it. – hmlasnk Jan 06 '16 at 15:56

1 Answers1

1
CAShapeLayer *mask = [[CAShapeLayer alloc] init];
mask.frame = imgTest.layer.bounds;
CGFloat width = imgTest.layer.frame.size.width;
CGFloat height = imgTest.layer.frame.size.height;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 0);
CGPathAddLineToPoint(path, nil, width, 0);
CGPathAddLineToPoint(path, nil, width-30, height);
CGPathAddLineToPoint(path, nil, 0, height);
CGPathAddLineToPoint(path, nil, 0, 0);
CGPathCloseSubpath(path); mask.path = path;
CGPathRelease(path);
imgTest.layer.mask = mask;
tuledev
  • 10,177
  • 4
  • 29
  • 49