0

I am trying to create a custom shape for a UIView, named 'CoverView'.

Currently I have the frame set to...

    [CoverView setFrame:CGRectMake(0, 0, 1808, 303)];

I wanted to create a custom shape for the UIView to have a 200x200 cut out from the top middle of the UIView. Basically, the cut out would have a frame of (804, 0, 200, 200).

Any help would greatly be appreciated.

OscarTheGrouch
  • 2,374
  • 4
  • 28
  • 39
  • A UIView is always rectangular, but maybe add a subview that has a background to match the background behind your coverview? – Andrew Tetlaw Jan 09 '13 at 00:59
  • I have the CoverView blocking a lot of buttons I don't want touched during certain operations in the app, but there is one button the CoverView is blocking that needs to be used. I see what you are saying about adding another subview, or in my case another button into the CoverView. I was hoping I could change the CoverView in some way to do what I was thinking of though. I was able to mask the CoverView but the button underneath still isn't usable. see the code below... – OscarTheGrouch Jan 09 '13 at 04:30
  • i used http://stackoverflow.com/questions/1054937/programmatically-send-to-front-back-elements-created-from-interface-builder to programmatically change the order of the button and the CoverView as needed, still doesn't look the way I want it to but it functions like it needs to. – OscarTheGrouch Jan 09 '13 at 04:57

1 Answers1

2

I was able to create a mask for the CoverView, which visually created what I was looking for but any buttons under the view's mask that could be seen were not able to be pressed because the CoverView was still over them. The code is below. Any suggestions on what to use to have buttons in the view's hole be able to be used?

CGMutablePathRef maskPath = CGPathCreateMutable();
        CGPathMoveToPoint(maskPath, NULL, 0, 0);
        CGPathAddLineToPoint(maskPath, NULL, 804, 0);
        CGPathAddLineToPoint(maskPath, NULL, 804, 200);
        CGPathAddLineToPoint(maskPath, NULL, 1004, 200);
        CGPathAddLineToPoint(maskPath, NULL, 1004, 0);
        CGPathAddLineToPoint(maskPath, NULL, 1808, 0);
        CGPathAddLineToPoint(maskPath, NULL, 1808, 303);
        CGPathAddLineToPoint(maskPath, NULL, 0, 303);
        CGPathAddLineToPoint(maskPath, NULL, 0, 0);
        CGPathCloseSubpath(maskPath);

        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = CoverView.bounds;
        maskLayer.path = maskPath;
        CoverView.layer.mask = maskLayer;
OscarTheGrouch
  • 2,374
  • 4
  • 28
  • 39