0

Is it possible to mask certain area of a view, so that content of that part became invisible/hidden.

I am using a web view and wanted to remove the top round corner of view, like below attached image - enter image description here

Problem -

I want to remove/hide all the content which is below red area.

What I have tried -

I have tried to add a image view on top of web view and added a masking layer on top of it, but that doesn't seems to be working for me -

UIImageView *maskImage = [[UIImageView alloc] init];
maskImage.frame = CGRectMake(256, -10, 64, 64);
maskImage.image = [UIImage imageNamed:@"maskingImage"];
[self.webView addSubview: maskImage];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGRect maskRect = whitefoldMaskImage.frame;//CGRectMake(0, 0, 50, 100);

CGPathRef path = CGPathCreateWithRect(maskRect, NULL);
maskLayer.path = path;
CGPathRelease(path);

maskImage.layer.mask = maskLayer;

EDIT 1 --

As per suggestion of Mundi, I have tried opaque view on top of web view.

 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(256, -10, 64, 64)];
 view.opaque = YES;
 [self.webView addSubview:view];

But that haven't worked too.

I have also gone through following threads on SO, but haven't found any solution -

CALayer: add a border only at one side

Simply mask a UIView with a rectangle

Community
  • 1
  • 1
rishi
  • 11,779
  • 4
  • 40
  • 59

1 Answers1

0

I want to remove/hide all the content which is below red area.

Simply add a opaque view above the area you want to hide. No need for a mask. E.g.

UIView *cover = [[UIView alloc] initWithFrame:topRightCornerFrame];
cover.backgroundColor = [UIColor whiteColor];
[webView addSubView:cover];
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Transparent opaque view is possible?? – rishi Jul 14 '14 at 10:41
  • i have tried using this but not working. still showing content behind that view – rishi Jul 14 '14 at 10:49
  • Did you set the backgroundcolor for the view? Otherwise it is just clearcolor – Amandir Jul 14 '14 at 11:19
  • @rishi "transparent opaque" view is possible by setting the `alpha` to a value between 0.0 and 1.0. – Mundi Jul 14 '14 at 11:39
  • don't want any color on that, want a kind of transparent effect on top of that.just hiding that area without any color. – rishi Jul 14 '14 at 12:01
  • You need a color. No color means invisible and you see through. Maybe you mean black? – Mundi Jul 14 '14 at 12:39
  • Which is why i was looking for masking options, i believe that is achievable some how. – rishi Jul 14 '14 at 16:17
  • You are not making yourself clear. Your image shows a red rectangle. The text of your question mentions a "round" corner. Can you make an image that shows what you want? – Mundi Jul 14 '14 at 19:07